diff --git a/README.md b/README.md index 767248c..0618716 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,13 @@ yield Storage.putFile('path/to/file/directory', contents) // File will be stored at `path/to/file/directory/filename` yield Storage.putFileAs('path/to/file/directory', contents, filename) +// Additional parameters can be passed to the S3 driver +yield Storage.putFile('/path/to/file', contents, {ContentType: 'image/jpeg'}) + // Return the url or absolute file path for accessing the file yield Storage.url('path/to/file') + ``` ## License diff --git a/src/Drivers/FileSystem.js b/src/Drivers/FileSystem.js index 83ea2d8..47feb24 100644 --- a/src/Drivers/FileSystem.js +++ b/src/Drivers/FileSystem.js @@ -71,7 +71,7 @@ class FileSystem { /** * Write contents to a file at `path`. */ - put (path, contents) { + put (path, contents, driverOpts={}) { const fullPath = this._fullPath(path) // Create directory if needed const pathWithoutFilename = fullPath.slice(0, fullPath.lastIndexOf('/')) diff --git a/src/Drivers/S3.js b/src/Drivers/S3.js index debac48..f180b71 100644 --- a/src/Drivers/S3.js +++ b/src/Drivers/S3.js @@ -14,7 +14,8 @@ class S3 { this.s3 = new AWS.S3({ accessKeyId: this.disk.key, secretAccessKey: this.disk.secret, - region: this.disk.region + region: this.disk.region, + signatureVersion: 'v4', }) } @@ -66,13 +67,13 @@ class S3 { /** * Write contents to a file at `path`. */ - * put (path, contents) { + * put (path, contents, driverOpts={}) { return new Promise((resolve, reject) => { - this.s3.upload({ + this.s3.upload(Object.assign({ Bucket: this.disk.bucket, Key: path, Body: contents - }, (err, data) => { + }, driverOpts), (err, data) => { if (err) return reject(err) return resolve(data.Location) }) diff --git a/src/Storage.js b/src/Storage.js index 11135a3..1b00f05 100644 --- a/src/Storage.js +++ b/src/Storage.js @@ -49,13 +49,14 @@ class Storage { * @param string $path * @param string|resource $contents * @param string $visibility + * @param object driveroptions * @return bool */ - * put (path, contents) { + * put (path, contents, driverOpts={}) { if (contents instanceof File) { return yield this.putFile(path, contents) } - return yield this.driver.put(path, contents) + return yield this.driver.put(path, contents, driverOpts) } /** @@ -63,11 +64,12 @@ class Storage { * * @param string path * @param {File} file + * @param object driveroptions * @return string|false */ - * putFile (path, file) { + * putFile (path, file, driverOpts={}) { const fileHash = yield md5File(file.file.path) - return yield this.putFileAs(path, file, fileHash) + return yield this.putFileAs(path, file, fileHash, driverOpts) } /** @@ -76,11 +78,12 @@ class Storage { * @param string path * @param {File} file * @param string name + * @param object driveroptions * @return string|false */ - * putFileAs (filePath, file, name) { + * putFileAs (filePath, file, name, driverOpts={}) { const stream = fs.createReadStream(file.file.path) - return yield this.put(path.join(filePath, name), stream) + return yield this.put(path.join(filePath, name), stream, driverOpts) } /**