0.11.3 • Published 5 months ago

@sensejs/multipart v0.11.3

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

High-level Multipart Body Parser

This package, @sensejs/multipart, provides a high-level multipart body parser based on @fastify/busboy that supports custom storage provider and back pressure. It does not depend on any other part of SenseJS, and can be used standalone with any other HTTP framework.

Usage

const [multipart, cleanup] = Multipart.from(req, req.headers);

try {
  const records = await multipart.read(new MultipartFileDiskStorage());
} finally {
  // By default, files stored by `MultipartFileDiskStorage` will be deleted when calling cleanup
  await cleanup();
}

If your app cannot access disk storage, and you only need to handle small files, you can just call await multipart.read() instead, which will by default to an instance of MultipartFileMemoryStorage that stores files in memory.

If you want to handle large files and persist them on a remote storage, you should implement a custom storage adaptor that derives from RemoteStorageAdaptor, and use it with MultipartFileRemoteStorage.

const [multipart, cleanup] = Multipart.from(req, req.headers);

try {
  const records = await multipart.read(new MultipartFileRemoteStorage(new YourRemoteStorageAdaptor()));
} finally {
  // It will invoke the cleanup method provided by your adaptor
  await cleanup();
}
0.11.3

5 months ago

0.11.2

12 months ago

0.11.1

1 year ago

0.11.0

1 year ago

0.11.0-alpha.3

1 year ago

0.11.0-alpha.2

1 year ago