Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gigasource/file-explorer-backend

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gigasource/file-explorer-backend

An Express middleware for uploading files

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

file-explorer-backend

1. Data structure

1.a Required properties

  // The name of the file
  fileName: String, 

  // The folder path of the file (e.g: '/home/', '/documents/work/')
  folderPath: String, 

  // MimeType of the file
  mimeType: String, 

  // If this record is a file or a folder
  isFolder: Boolean, 

  // Size of the file when saved in storage
  sizeInBytes: Number, 

  // File stored on storage system to get the file when needed
  // For example: 
  // if the storage system is S3 or Bunny CDN, it can be an URL: https://bunny/file.txt
  // if the storage system is GridFS, it is the ObjectId of the 'files' collection
  fileSource: String, 

1.b Optional properties

  // FileName saved on storage system
  generatedFileName: String,

  // If namespace middleware is used
  namespace: String, 

An example of file metadata object:

{
  "fileName": "file.txt",
  "mimeType": "text/plain",
  "folderPath": "/home/docs/",
  "sizeInBytes": "123",
  "isFolder": true,
  "generatedFileName": "random-file-name-65G9-GFDGFD-543534GDV-GT34GFDGDF.txt",
  "namespace": "user-admin-1",
  "fileSource": "https://bunnycdn/578543785348.txt (or an ObjectId: 8501859174829234 (GridFS))"
}

1.c How to customize property names

Pass an mapping object in initFileExplorer function like this:

const {
    uploadFile,
    downloadFile,
    otherApis,
  } = initFileExplorer({
    dependencies: {
      fileMetadataStorage: mongooseFileMetadataStorage,
      fileStorage: gridFsFileStorage,
    },
    propertyMappings: {
      fileName: "name",
      mimeType: "mime",
      folderPath: "folder",
      sizeInBytes: "size",
    }
  });

Then file metadata object will be returned and saved in database with new property names:

{
  "name": "file.txt",
  "mime": "text/plain",
  "folder": "/home/docs/",
  "size": "123",
  "isFolder": true, (this prop is not mapped so the name will be the default name)
  ...
}

2. Code example

Check repository https://github.com/gigasource/file-explorer for examples

3. Roadmap

  • Do property mappings for request queries and body
  • Handle error messages

FAQs

Package last updated on 23 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc