Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added signatureVersion to S3 init to support newer regions #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('/'))
Expand Down
9 changes: 5 additions & 4 deletions src/Drivers/S3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
}

Expand Down Expand Up @@ -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)
})
Expand Down
15 changes: 9 additions & 6 deletions src/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,27 @@ 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)
}

/**
* Store the uploaded file with name as md5 hash of file contents
*
* @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)
}

/**
Expand All @@ -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)
}

/**
Expand Down