S3
S3 copied to clipboard
Get file name of photo uploaded
I'm trying to get the file name of an uploaded photo to save in the database. How would I do that?
Here is my code:
var files = $("input.file_bag")[0].files;
var caseId = this._id;
var firmName = Firms.findOne(Meteor.user().firm_id).name;
var clientName = this.client_name;
var cleanClientname = clientName.split(' ').join('-');
S3.upload({
files: files,
path: firmName + "/client-photos/" + cleanClientname
}, function(err, res){
if (err) {
sAlert.error("Upload Error: " + err.reason);
throw new Meteor.Error("Upload Error: " + err.reason);
} else {
Meteor.call('photoInsert', caseId, res.secure_url, res.relative_url, res.total, function (err2) {
if (err2) {
sAlert.error("Photo Upload Error: " + err2.reason);
}
});
}
});
Hi! $("input.file_bag")[0].files is an array of Files (AKA: FileList Object). If you run an each statement you can find the names for each file that way.
Sure, but I'm curious as to whether I have access to the current file object being uploaded within the callback of the upload function? This is my post on the meteor forums: https://forums.meteor.com/t/get-filename-of-uploaded-file-with-lepozepo-s3/5354
That's something I could probably add on. I'll have a look tonight hopefully.
That would be awesome, thanks!
:+1: