Skip to content

Commit

Permalink
Merge cbf1716 into df82c77
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Voss committed Aug 30, 2018
2 parents df82c77 + cbf1716 commit 895c152
Show file tree
Hide file tree
Showing 5 changed files with 2,999 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,9 @@ PostSchema.plugin(crate, {
scope: '<scope-here>', // defaults to https://www.googleapis.com/auth/devstorage.full_control
acl: '<acl-here>', // defaults to public-read
path: (attachment) => `/${path.basename(attachment.path)}` // where the file is stored in the bucket - defaults to this function
headers: { // Optinoal headers sendt to gcs
'Cache-Control': 'private'
}
}),
fields: {
file: {}
Expand Down
19 changes: 14 additions & 5 deletions lib/GCS.js
Expand Up @@ -54,16 +54,25 @@ class GCSStorageProvider extends EventEmitter {
})
}

createHeaders (attachment) {
var headers = {
'Content-Length': attachment.size,
'Content-Type': attachment.type,
'x-goog-acl': this._options.acl
}
if (!this._options.headers) { return headers }
for (var header in this._options.headers) {
headers[header] = this._options.headers[header]
}
return headers
}

save (attachment, callback) {
if (!this._client) {
return this.on('connected', this.save.bind(this, attachment, callback))
}

this._client.putStream(fs.createReadStream(attachment.path), this._options.bucket, this._options.path(attachment), {
'Content-Length': attachment.size,
'Content-Type': attachment.type,
'x-goog-acl': this._options.acl
}, function (error, response) {
this._client.putStream(fs.createReadStream(attachment.path), this._options.bucket, this._options.path(attachment), this.createHeaders(attachment), function (error, response) {
callback(error, error ? undefined : response.request.href)
})
}
Expand Down

0 comments on commit 895c152

Please sign in to comment.