Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

feathers-blob

Feathers blob service

feathers, feathers-plugin, blob, abstract-blob-store, fs, s3, file, files, binary

readme

feathers-blob

Node.js CI Dependency Status Download Status

Feathers abstract blob store service

Installation

npm install feathers-blob --save

Also install a abstract-blob-store compatible module.

API

const BlobService = require('feathers-blob')

blobService = BlobService(options)

  • options.Model is an instantiated interface that implements the abstract-blob-store API
  • options.id is a string 'key' for the blob identifier.
  • returnUri defaults is true, set it to false to remove it from output.
  • returnBuffer defaults is false , set it to true to return buffer in the output.

Tip: returnUri/returnBuffer are mutually exclusive.

If you only want a buffer output instead of a data URI on create/get operations, you need to set returnBuffer to be true, also to set retuarnUri to be false.

If you need both, use the default options, then extract the buffer from the data URI on the client-side to avoid transferring the data twice over the wire.

blobService.create(body, params)

where input body is an object with either:

  • a key uri pointing to data URI of the blob,
  • a key buffer pointing to raw data buffer of the blob along with its contentType (i.e. MIME type).

Optionally, you can specify in the body the blob id which can be the file path where you want to store the file, otherwise it would default to ${hash(content)}.${extension(contentType)}.

Tip: You can use feathers hooks to customize the id. You might not want the client-side to write whereever they want.

returns output 'data' of the form:

{
  [this.id]: `${hash(content)}.${extension(contentType)}`,
  uri: body.uri, // When returnUri options is set true
  buffer: body.buffer, // When returnBuffer options is set true
  size: length(content)
}

blobService.get(id, params)

returns output data of the same form as create.

blobService.remove(id, params)

Params:

Query:

  • VersionId (string): Version ID of document to access if using a versioned s3 bucket

Example:

blobService.get('my-file.pdf', {
  query: {VersionId: 'xslkdfjlskdjfskljf.sdjfdkjfkdjfd'},
})

Example

const { getBase64DataURI } = require('dauria');
const AWS = require('aws-sdk');
const S3BlobStore = require('s3-blob-store');
const feathers = require('@feathersjs/feathers');
const BlobService = require('feathers-blob');

const s3 = new AWS.S3({
  endpoint: 'https://{service}.{region}.{provider}.com',
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});

const blobStore = S3BlobStore({
  client: s3,
  bucket: 'feathers-blob'
});

const blob = {
  uri: getBase64DataURI(new Buffer('hello world'), 'text/plain')
}

const app = feathers();

app.use('/upload', BlobService({
  Model: blobStore
}));

const blobService = app.service('upload');

blobService.create(blob).then(function (result) {
  console.log('Stored blob with id', result.id);
}).catch(err => {
  console.error(err);
});

Should you need to change your bucket's options, such as permissions, pass a params.s3 object using a before hook.

app.service('upload').before({
  create(hook) {
    hook.params.s3 = { ACL: 'public-read' }; // makes uploaded files public
  }
});

For a more complete example, see examples/app which can be run with npm run example.

Tests

Tests can be run by installing the node modules and running npm run test.

To test the S3 read/write capabilities set the environmental variable S3_BUCKET to the name of a bucket you have read/write access to. Enable the versioning functionality on the bucket.

License

Copyright (c) 2018

Licensed under the MIT license.

changelog

Changelog

v2.5.0 (2021-04-25)

Full Changelog

Closed issues:

  • Could we have the contentType in the create result ? #83

Merged pull requests:

  • Add contentType in get / create response #85 (mdartic)
  • Move CI to GitHub action #84 (daffl)

v2.4.0 (2021-04-15)

Full Changelog

Closed issues:

  • Typescript: Cannot use namespace 'AbstractBlobStore' as a type #81

Merged pull requests:

v2.3.0 (2020-10-04)

Full Changelog

Implemented enhancements:

  • Add TypeScript definitions #78

Closed issues:

  • Metadata does not been used on cb of createWriteStream #80
  • docs: how to use feathers-blob with typescript #77
  • passing option returnUri: false and returns uri... #75
  • How to render uploaded photos? #74

Merged pull requests:

v2.2.0 (2019-12-18)

Full Changelog

Implemented enhancements:

  • Make data uri encoding optional #69
  • Support Multipart File Upload #25

Fixed bugs:

  • Extension can be ".false" if mime type is not recognized #47
  • feathers client resolves to service path instead of store model on get and remove #4

Closed issues:

  • docs: get does not return buffer #71
  • Large file upload to S3 errors with TimeOut from S3 #67

Merged pull requests:

v2.1.0 (2019-03-09)

Full Changelog

Closed issues:

  • An in-range update of debug is breaking the build 🚨 #61
  • feathers blobs service save docx with .bin extension #59
  • An in-range update of aws-sdk is breaking the build 🚨 #58
  • An in-range update of aws-sdk is breaking the build 🚨 #55
  • An in-range update of aws-sdk is breaking the build 🚨 #54
  • An in-range update of aws-sdk is breaking the build 🚨 #53
  • An in-range update of aws-sdk is breaking the build 🚨 #51
  • An in-range update of aws-sdk is breaking the build 🚨 #50
  • An in-range update of aws-sdk is breaking the build 🚨 #49

Merged pull requests:

v2.0.1 (2018-06-03)

Full Changelog

Closed issues:

  • get() does not work with latest s3-blob-store (v3.0.0) #37
  • How to resize an image before create it ? #35
  • So I need help pointing me in right direction, I would like to return a like to return a file url instead of base64 #18

Merged pull requests:

v2.0.0 (2018-03-09)

Full Changelog

Closed issues:

  • Custom ID not returned on remove #39

Merged pull requests:

  • Upgrade to Feathers v3 and latest plugin infrastructure #43 (daffl)
  • Finalize S3 tests #42 (daffl)
  • Added tests for S3 blob store #38 (claustres)

v1.5.0 (2018-03-07)

Full Changelog

Merged pull requests:

  • Added support to create blob from raw buffer #41 (claustres)

v1.4.1 (2018-03-02)

Full Changelog

Merged pull requests:

v1.4.0 (2018-02-16)

Full Changelog

Closed issues:

  • List of files/blob #5

Merged pull requests:

v1.3.1 (2017-06-30)

Full Changelog

Merged pull requests:

  • Reject if Model.createWriteStream returns with error #24 (3bola)

v1.3.0 (2017-06-21)

Full Changelog

Closed issues:

  • How to change upload folder dynamically? #21
  • del #15
  • Get this repo consistent with all other repos #10

Merged pull requests:

v1.2.0 (2016-08-18)

Full Changelog

Closed issues:

  • Unable to set ACL permissions for S3 #7
  • unsupported mime types #6

Merged pull requests:

v1.1.0 (2016-06-17)

Full Changelog

Closed issues:

  • Why datauris? #2

Merged pull requests:

v1.0.5 (2016-04-03)

Full Changelog

Merged pull requests:

v1.0.4 (2016-03-05)

Full Changelog

v1.0.3 (2016-03-01)

Full Changelog

v1.0.2 (2016-02-29)

Full Changelog

1.0.1 (2016-02-29)

Full Changelog

v1.0.1 (2016-02-29)

Full Changelog

1.0.0 (2016-02-23)

Full Changelog

* This Changelog was automatically generated by github_changelog_generator