-
Notifications
You must be signed in to change notification settings - Fork 37
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
Feature Request: Specify s3 Path #33
Comments
Hello! Checkout the keyTransform (nameTransform)Type: Use this to transform your file names before they're uploaded to your S3 bucket. gulp.task("upload_transform", function() {
return gulp.src("./dir/to/upload/**")
.pipe(s3({
Bucket: 'example-bucket',
ACL: 'public-read',
keyTransform: function(relative_filename) {
var new_name = changeFileName(relative_filename);
// or do whatever you want
return new_name;
}
}))
;
}); So, if you want to prepend the folder name... gulp.task("upload_transform", function() {
return gulp.src("./dir/to/upload/**")
.pipe(s3({
Bucket: 'example-bucket',
ACL: 'public-read',
keyTransform: function(relative_filename) {
var new_name = "folder/to/upload/to/" + relative_filename;
// or you can use `path.join("folder", "to", "upload", relative_filename)`
return new_name;
}
}))
;
}); |
Great, thanks for this! Sent from my iPhone
|
This method is great but it does not allow me to specify prefix for example. Is there any way to keep the folder structure and prefix all uploads with a path? gulp.src(["index.html",'./assets/**'])
.pipe(s3({
Bucket: 'mybucket',
ACL: 'public-read',
keyTransform: function(relative_filename) {
var new_name = "production/" + relative_filename; // causes issue, since all keys will be prefixed but original path is not used
return new_name;
}
}, |
This is my solution (workaround) if(keyTransform) {
// Allow the transform function to take the
// complete path in case the user wants to change
// the path of the file, too.
// >>>>>>> change here: file.relative to: file.path
keyname = keyTransform(file.path);
} else {
// ...Otherwise keep it exactly parallel.
keyparts = helper.parsePath(file.relative);
keyname = helper.buildName(keyparts.dirname, keyparts.basename + keyparts.extname);
} and after that: const targetAssets = 'aws-assets/';
gulp.src(["index.html",'./assets/**'])
.pipe(s3({
Bucket: 'mybucket',
ACL: 'public-read',
keyTransform: function(filePath) {
let newFile = targetAssets + filePath.split("www/assets/")[1]
return newFile;
}
}, for example: |
Is is possible to add an option to specify the upload path? AWS API suggests prepending the file name with
/folder/to/upload/to/
. Can't figure out how to implement this here.The text was updated successfully, but these errors were encountered: