New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

parse-server-multi-files-adapter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-server-multi-files-adapter

Allows multiple file adapters to be used at the same time by specifying the adapter in the filename.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

parse-server-multi-files-adapter npm version

Allows multiple file adapters to be used at the same time by specifying the adapter in the filename.

Installation

yarn add parse-server-multi-files-adapter

or

npm install --save parse-server-multi-files-adapter

Usage

Server

For now, must be passed as an instance to the parse-server constructor:

const MultiFilesAdapter = require('parse-server-multi-files-adapter')
const FSFilesAdapter = require('parse-server-fs-adapter')
const S3Adapter = require('parse-server-s3-adapter')
const GCSAdapter = require('parse-server-gcs-adapter')

const multiAdapter = new MultiFilesAdapter({
  // Delimiter used to retrieve adapter key
  // Never change this
  id: 'unique', 
  
  // Dictionary of file adapters
  adapters: {
    local: new FSFilesAdapter(),
    s3: new S3Adapter({
      // options...
    }),
    gcs1: new GCSAdapter({
      // options...
    }),
    gcs2: new GCSAdapter({
      // options...
    })
  },
  
  // The key of the file adapter to use if none specified
  // Never change this
  defaultAdapter: 's3'
})

const api = new ParseServer({
  appId: 'app_id',
  masterKey: 'master_key',
  filesAdapter: multiAdapter
})

Client

The adapter key (corresponding to a key in the adapters object above) must be embedded in the filename. This uses subsume-limited to parse the filename and determine the adapter key. If writing a JS app you could do something like this to help create files:

// Utils
const Subsume = require('subsume-limited')

const subsume = new Subsume('unique') // same id that was passed to constructor on server

function composeFileName (adapterKey, filename) {
  return subsume.compose(adapterKey) + filename
}

function getOriginalFileName (filename) {
  return subsume.parse(filename).rest
}

function createParseFile (adapterKey, filename, data, type) {
  return new Parse.File(composeFileName(adapterKey, filename), data, type)
}

// Usage
const file = createParseFile('local', 'foobar.txt', { base64: "TG9yZW0gSXBzdW0gRG9sb3I=" })

file.save()
    .then(function () {
      const foo = new Parse.Object('Foo')
      foo.set('file', file)
      return foo.save()
    })
    .then(function () {
      console.log('Saved')
    })

The saved file name in the example above would be Qq-unique-qQlocalZz-unique-zZfoobar.txt. If not using JS, you can replicate that functionality:

ID = Delimiter you chose
AdapterKey = Key of adapter to use
prefix = "Qq-" + ID + "-qQ"
suffix = "Zz-" + ID + "-zZ"
composed = prefix + AdapterKey + suffix
filename = composed + original file name

FAQs

Package last updated on 30 Jul 2017

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