Skip to content

Commit

Permalink
docs: storage: show better getSignedUrl examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Aug 14, 2015
1 parent 14523d3 commit adbe612
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -1153,11 +1153,52 @@ File.prototype.getSignedPolicy = function(options, callback) {
* @param {string} callback.url - The signed URL.
*
* @example
* var request = require('request');
* var TWO_WEEKS_MS = Math.round(Date.now() / 1000) + (60 * 60 * 24 * 14);
*
* //-
* // Generate a URL that allows temporary access to download your file.
* //-
* file.getSignedUrl({
* 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

0 comments on commit adbe612

Please sign in to comment.