From 87fb610ce237a4cc44cfa17054919f99a2739fc2 Mon Sep 17 00:00:00 2001 From: Jerome Touffe-Blin Date: Tue, 16 Sep 2014 19:12:09 +1000 Subject: [PATCH] Allow uploading a file to a different name --- README.md | 13 +++++++++++++ index.js | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 041c133..6980957 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,19 @@ gulp.src('./dist/**') }); ``` +#### options.dest + +Type: `String` +Default: `` + +Upload file to a different destination name. + +```javascript +var options = { dest: 'foobar.png } +gulp.src('./dist/barfoo.png') + .pipe(s3(aws, options)); +``` + ## License [MIT License](http://en.wikipedia.org/wiki/MIT_License) diff --git a/index.js b/index.js index d2b537f..a06362e 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,6 @@ module.exports = function (aws, options) { if (!options.delay) { options.delay = 0; } var client = knox.createClient(aws); - var waitTime = 0; var regexGzip = /\.([a-z]{2,})\.gz$/i; var regexGeneral = /\.([a-z]{2,})$/i; @@ -21,7 +20,10 @@ module.exports = function (aws, options) { // Verify this is a file if (!file.isBuffer()) { return file; } - var uploadPath = file.path.replace(file.base, options.uploadPath || ''); + var uploadPath = options.dest ? + options.dest : + file.path.replace(file.base, options.uploadPath || ''); + uploadPath = uploadPath.replace(new RegExp('\\\\', 'g'), '/'); var headers = { 'x-amz-acl': 'public-read' }; if (options.headers) {