Skip to content
Merged
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
48 changes: 45 additions & 3 deletions lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -1156,11 +1156,53 @@ File.prototype.getSignedPolicy = function(options, callback) {
* @param {string} callback.url - The signed URL.
*
* @example
* var TWO_WEEKS_MS = Math.round(Date.now() / 1000) + (60 * 60 * 24 * 14);
*
* //-
* // Generate a URL that allows temporary access to download your file.
* //-
* var request = require('request');
*
* file.getSignedUrl({

This comment was marked as spam.

This comment was marked as spam.

* action: 'read',
* expires: Math.round(Date.now() / 1000) + (60 * 60 * 24 * 14), // 2 weeks.
* promptSaveAs: 'filename.ext'
* }, function(err, url) {});
* expires: TWO_WEEKS_MS
* }, function(err, url) {
* if (err) {
* console.error(err);
* return;
* }
*
* // The file is now available to read from this URL.
* request(url, function(err, resp) {
* // resp.statusCode = 200
* });
* });
*
* //-
* // Generate a URL to allow write permissions. This means anyone with this URL
* // can send a POST request with new data that will overwrite the file.
* //-
* file.getSignedUrl({
* action: 'write',
* expires: TWO_WEEKS_MS
* }, function(err, url) {
* if (err) {
* console.error(err);
* return;
* }
*
* // The file is now available to be written to.
* var writeStream = request.post(url);
* writeStream.end('New data');
*
* writeStream.on('complete', function(resp) {
* // Confirm the new content was saved.
* file.download(function(err, fileContents) {
* console.log('Contents:', fileContents.toString());
* // Contents: New data
* });
* });
* });
*/
File.prototype.getSignedUrl = function(options, callback) {
if (options.expires < Math.floor(Date.now() / 1000)) {
Expand Down