Closed nidhi95 closed 5 years ago
:+1: for this issue. I am currently having a problem with trying to upload to a folder under a S3 bucket.
Hi,
you can use the saveAs option:
req.file('file')
.upload({
adapter: require('skipper-s3'),
key: 'key',
secret: 'secret',
bucket: 'bucket_name',
saveAs: 'folder_name/file'
})
Ok, wow. I'm not sure how I missed that. I ended up actually neededing dirname
. I wanted to place some audio files under an audio folder.
thank you
Although saveAs
works. I'm not sure how to leverage it the way I need?
req.file('song').upload({
adapter: skipperS3,
key: sails.config.aws.s3.accessKeyId,
secret: sails.config.aws.s3.secretAccessKey,
saveAs: 'audio/test.png',
bucket: 'music-tribe'
}, function (error, updoadedFiles) {
if (error) {
return res.serverError(error);
}
return res.redirect('/dashboard');
});
Here are my problems.
uuid
for the fil name myself.dirName
property, but it didn't seem to work.Any thoughts on this?
A possible solution is here (http://stackoverflow.com/questions/23977005/uploading-files-using-skipper-with-sails-js-v0-10-how-to-retrieve-new-file-nam).
This seems like a large amount of work for what I think should already exist.
@vikeen Thanks for posting your research! It'll be especially helpful for folks finding this issue via search.
This seems like a large amount of work for what I think should already exist. Agreed-- although I think specifying a function for
saveAs
would solve this problem, right? I think we need to expand the docs on the subject though, since I don't see anything about how to access the filename from the stream in the README.
So in the example you posted:
req.file('song').upload({
adapter: skipperS3,
key: sails.config.aws.s3.accessKeyId,
secret: sails.config.aws.s3.secretAccessKey,
saveAs: function (file) {
var origFilename = file.filename;
var origExtension = require('path').extname(file.filename);
return 'whatever/transmographied/filename/you/want.png';
},
bucket: 'music-tribe'
}, function (error, uploadedFiles) {
if (error) {
return res.serverError(error);
}
return res.redirect('/dashboard');
});
I'd love to see a proposal with some thoughts on how we could improve the docs on this if you have time.
btw- speaking of docs, on a separate note, if anyone's got a few minutes, I think it would be a good idea to bring in documentation for Upstreams'
.upload()
method into sails-docs reference so it can be rendered as HTML (will make this all easier to read). Could convert http://sailsjs.org/documentation/reference/request-req/req-file into a folder and createupload
as a markdown file inside.
Thanks!
@mikermcneil I was able to solve the problem like this.
/**
* FilesController
* @description :: Server-side logic for files
*/
import fs from 'fs';
import _ from 'lodash';
import skipperS3 from 'skipper-s3';
export function upload(req, res, next) {
var originalFileName = req.file('file')._files[0].stream.filename,
contentType = FileService.getContentTypeFromFileExtention(originalFileName);
sails.log.verbose("attempting to upload file [%s] as file type [%s]", originalFileName, contentType);
req.file('file').upload({
adapter: skipperS3,
key: sails.config.aws.s3.accessKeyId,
secret: sails.config.aws.s3.secretAccessKey,
dirname: contentType,
bucket: 'music-tribe'
}, function (error, updoadedFiles) {
if (error) {
return res.serverError(error);
} else {
// do stuff
});
}
The problem was me calling dirName
instead of dirname
for the s3 upload config.
However, it was not clear to me that core features of the knox client were being inherited via skipper and then to skipper-s3 (e.g. saveAs
and dirname
). Maybe that's worth noting on the plugins?
Thanks for posting, @nidhi95. I'm a repo bot-- nice to meet you!
It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:
Thanks so much for your help!
I would like to store data in "bucket_name/folder_name/file"