{"_id":"@come25136/multer-s3","_rev":"2-8d15baa249089ae558dea85b78539b92","name":"@come25136/multer-s3","description":"Streaming multer storage engine for AWS S3","dist-tags":{"latest":"2.8.0"},"versions":{"2.8.0":{"name":"@come25136/multer-s3","version":"2.8.0","description":"Streaming multer storage engine for AWS S3","main":"index.js","scripts":{"test":"standard && mocha test/basic.js"},"repository":{"type":"git","url":"git+https://github.com/come25136/multer-s3.git"},"keywords":["multer","s3","amazon","aws"],"author":{"name":"come25136"},"license":"MIT","bugs":{"url":"https://github.com/come25136/multer-s3/issues"},"homepage":"https://github.com/come25136/multer-s3#readme","dependencies":{"file-type":"^7.2.0","run-parallel":"^1.1.6"},"devDependencies":{"aws-sdk":"^2.2.32","concat-stream":"^1.5.1","express":"^4.13.1","form-data":"^2.3.1","mocha":"^4.0.1","multer":"^1.1.0","on-finished":"^2.3.0","standard":"^10.0.3","xtend":"^4.0.1"},"gitHead":"aa1bef55cbba4be77bbd87681f66a6469a2d33a2","_id":"@come25136/multer-s3@2.8.0","_shasum":"3f0a0f92b6eb2ca9dbde5f3ea1e18a5695739307","_from":".","_npmVersion":"4.0.5","_nodeVersion":"8.8.1","_npmUser":{"name":"come25136","email":"come25136@gmail.com"},"dist":{"shasum":"3f0a0f92b6eb2ca9dbde5f3ea1e18a5695739307","tarball":"https://registry.npmjs.org/@come25136/multer-s3/-/multer-s3-2.8.0.tgz","integrity":"sha512-621cILMwmPE3IGb79kjlAIx3MSxU6JCa7dq07d3WAz1NJL33YT75uuFMUXJ5J6iqx2ifBKA9Wyn51BK/R4EMzg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCKxQ/uNz45sc3O+uWyJ7ScVdkWDWvlVUZ8hMfRSlPw/wIhALnHfEhpKCycXYVR20QI5OjhQJCWTjYOtY1BwkgANepL"}]},"maintainers":[{"name":"come25136","email":"come25136@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/multer-s3-2.8.0.tgz_1510637708977_0.07248702156357467"}}},"readme":"# Multer S3\r\n\r\nStreaming multer storage engine for AWS S3.\r\n\r\nThis project is mostly an integration piece for existing code samples from Multer's [storage engine documentation](https://github.com/expressjs/multer/blob/master/StorageEngine.md) with [s3fs](https://github.com/RiptideElements/s3fs) as the substitution piece for file system.  Existing solutions I found required buffering the multipart uploads into the actual filesystem which is difficult to scale.\r\n\r\n## Installation\r\n\r\n```sh\r\nnpm install --save multer-s3\r\n```\r\n\r\n## Usage\r\n\r\n```javascript\r\nvar aws = require('aws-sdk')\r\nvar express = require('express')\r\nvar multer = require('multer')\r\nvar multerS3 = require('multer-s3')\r\n\r\nvar app = express()\r\nvar s3 = new aws.S3({ /* ... */ })\r\n\r\nvar upload = multer({\r\n  storage: multerS3({\r\n    s3: s3,\r\n    bucket: 'some-bucket',\r\n    metadata: function (req, file, cb) {\r\n      cb(null, {fieldName: file.fieldname});\r\n    },\r\n    key: function (req, file, cb) {\r\n      cb(null, Date.now().toString())\r\n    }\r\n  })\r\n})\r\n\r\napp.post('/upload', upload.array('photos', 3), function(req, res, next) {\r\n  res.send('Successfully uploaded ' + req.files.length + ' files!')\r\n})\r\n```\r\n\r\n### File information\r\n\r\nEach file contains the following information exposed by `multer-s3`:\r\n\r\nKey | Description | Note\r\n--- | --- | ---\r\n`size` | Size of the file in bytes |\r\n`bucket` | The bucket used to store the file | `S3Storage`\r\n`key` | The name of the file | `S3Storage`\r\n`acl` | Access control for the file | `S3Storage`\r\n`contentType` | The `mimetype` used to upload the file | `S3Storage`\r\n`metadata` | The `metadata` object to be sent to S3 | `S3Storage`\r\n`location` | The S3 `url` to access the file  | `S3Storage`\r\n`etag` | The `etag`of the uploaded file in S3  | `S3Storage`\r\n`contentDisposition` | The `contentDisposition` used to upload the file | `S3Storage`\r\n`storageClass` | The `storageClass` to be used for the uploaded file in S3 | `S3Storage`\r\n\r\n### Setting ACL\r\n\r\n[ACL values](http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl) can be set by passing an optional `acl` parameter into the `multerS3` object.\r\n\r\n```javascript\r\nvar upload = multer({\r\n  storage: multerS3({\r\n    s3: s3,\r\n    bucket: 'some-bucket',\r\n    acl: 'public-read',\r\n    key: function (req, file, cb) {\r\n      cb(null, Date.now().toString())\r\n    }\r\n  })\r\n})\r\n```\r\n\r\nAvailable options for canned ACL.\r\n\r\nACL Option | Permissions added to ACL\r\n--- | ---\r\n`private` | Owner gets `FULL_CONTROL`. No one else has access rights (default).\r\n`public-read` | Owner gets `FULL_CONTROL`. The `AllUsers` group gets `READ` access.\r\n`public-read-write` | Owner gets `FULL_CONTROL`. The `AllUsers` group gets `READ` and `WRITE` access. Granting this on a bucket is generally not recommended.\r\n`aws-exec-read` | Owner gets `FULL_CONTROL`. Amazon EC2 gets `READ` access to `GET` an Amazon Machine Image (AMI) bundle from Amazon S3.\r\n`authenticated-read` | Owner gets `FULL_CONTROL`. The `AuthenticatedUsers` group gets `READ` access.\r\n`bucket-owner-read` | Object owner gets `FULL_CONTROL`. Bucket owner gets `READ` access. If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.\r\n`bucket-owner-full-control` | Both the object owner and the bucket owner get `FULL_CONTROL` over the object. If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.\r\n`log-delivery-write` | The `LogDelivery` group gets `WRITE` and `READ_ACP` permissions on the bucket. For more information on logs.\r\n\r\n## Setting Metadata\r\n\r\nThe `metadata` option is a callback that accepts the request and file, and returns a metadata object to be saved to S3.\r\n\r\nHere is an example that stores all fields in the request body as metadata, and uses an `id` param as the key: \r\n\r\n```javascript\r\nvar opts = {\r\n    s3: s3,\r\n    bucket: config.originalsBucket,\r\n    metadata: function (req, file, cb) {\r\n      cb(null, Object.assign({}, req.body));\r\n    },\r\n    key: function (req, file, cb) {\r\n      cb(null, req.params.id + \".jpg\");\r\n    }\r\n  };\r\n```\r\n\r\n## Setting Cache-Control header\r\n\r\nThe optional `cacheControl` option sets the `Cache-Control` HTTP header that will be sent if you're serving the files directly from S3. You can pass either a string or a function that returns a string.\r\n\r\nHere is an example that will tell browsers and CDNs to cache the file for one year:\r\n\r\n```javascript\r\nvar upload = multer({\r\n  storage: multerS3({\r\n    s3: s3,\r\n    bucket: 'some-bucket',\r\n    cacheControl: 'max-age=31536000',\r\n    key: function (req, file, cb) {\r\n      cb(null, Date.now().toString())\r\n    }\r\n  })\r\n})\r\n```\r\n\r\n## Setting Custom Content-Type\r\n\r\nThe optional `contentType` option can be used to set Content/mime type of the file. By default the content type is set to `application/octet-stream`. If you want multer-s3 to automatically find the content-type of the file, use the `multerS3.AUTO_CONTENT_TYPE` constant. Here is an example that will detect the content type of the file being uploaded.\r\n\r\n```javascript\r\nvar upload = multer({\r\n  storage: multerS3({\r\n    s3: s3,\r\n    bucket: 'some-bucket',\r\n    contentType: multerS3.AUTO_CONTENT_TYPE,\r\n    key: function (req, file, cb) {\r\n      cb(null, Date.now().toString())\r\n    }\r\n  })\r\n})\r\n```\r\nYou may also use a function as the `contentType`, which should be of the form `function(req, file, cb)`.\r\n\r\n## Setting StorageClass\r\n\r\n[storageClass values](https://aws.amazon.com/s3/storage-classes/) can be set by passing an optional `storageClass` parameter into the `multerS3` object.\r\n\r\n```javascript\r\nvar upload = multer({\r\n  storage: multerS3({\r\n    s3: s3,\r\n    bucket: 'some-bucket',\r\n    acl: 'public-read',\r\n    storageClass: 'REDUCED_REDUNDANCY',\r\n    key: function (req, file, cb) {\r\n      cb(null, Date.now().toString())\r\n    }\r\n  })\r\n})\r\n```\r\n\r\n## Setting Content-Disposition\r\n\r\nThe optional `contentDisposition` option can be used to set the `Content-Disposition` header for the uploaded file. By default, the `contentDisposition` isn't forwarded. As an example below, using the value `attachment` forces the browser to download the uploaded file instead of trying to open it.\r\n\r\n```javascript\r\nvar upload = multer({\r\n  storage: multerS3({\r\n    s3: s3,\r\n    bucket: 'some-bucket',\r\n    acl: 'public-read',\r\n    contentDisposition: 'attachment',\r\n    key: function (req, file, cb) {\r\n      cb(null, Date.now().toString())\r\n    }\r\n  })\r\n})\r\n```\r\n\r\n## Using Server-Side Encryption\r\n\r\n*An overview of S3's server-side encryption can be found in the [S3 Docs] (http://docs.aws.amazon.com/AmazonS3/latest/dev/serv-side-encryption.html); be advised that customer-managed keys (SSE-C) is not implemented at this time.*\r\n\r\nYou may use the S3 server-side encryption functionality via the optional `serverSideEncryption` and `sseKmsKeyId` parameters. Full documentation of these parameters in relation to the S3 API can be found [here] (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property) and [here] (http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html). \r\n\r\n`serverSideEncryption` has two valid values: 'AES256' and 'aws:kms'. 'AES256' utilizes the S3-managed key system, while 'aws:kms' utilizes the AWS KMS system and accepts the optional `sseKmsKeyId` parameter to specify the key ID of the key you wish to use. Leaving `sseKmsKeyId` blank when 'aws:kms' is specified will use the default KMS key. **Note:** *You must instantiate the S3 instance with `signatureVersion: 'v4'` in order to use KMS-managed keys [[Docs]] (http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html#specify-signature-version), and the specified key must be in the same AWS region as the S3 bucket used.*\r\n\r\n```javascript\r\nvar upload = multer({\r\n  storage: multerS3({\r\n    s3: s3,\r\n    bucket: 'some-bucket',\r\n    acl: 'authenticated-read',\r\n    contentDisposition: 'attachment',\r\n    serverSideEncryption: 'AES256',\r\n    key: function(req, file, cb) {\r\n      cb(null, Date.now().toString())\r\n    }\r\n  })\r\n})\r\n```\r\n\r\n## Testing\r\n\r\nThe tests mock all access to S3 and can be run completely offline.\r\n\r\n```sh\r\nnpm test\r\n```\r\n","maintainers":[{"name":"come25136","email":"come25136@gmail.com"}],"time":{"modified":"2022-06-12T16:23:06.216Z","created":"2017-11-14T05:35:09.129Z","2.8.0":"2017-11-14T05:35:09.129Z"},"homepage":"https://github.com/come25136/multer-s3#readme","keywords":["multer","s3","amazon","aws"],"repository":{"type":"git","url":"git+https://github.com/come25136/multer-s3.git"},"author":{"name":"come25136"},"bugs":{"url":"https://github.com/come25136/multer-s3/issues"},"license":"MIT","readmeFilename":"README.md"}