Get filename of uploaded file with lepozepo:s3


#1

I may be just struggling today but I can’t seem to figure out how to get the name of the file that I’m uploading with lepozepo:s3. 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);
                }
            });
        }
    });

How would I grab the name of the uploaded file so that I can pass it to the photoInsert method?

I could just have a counter at the top:

var counter = 0

and then use:

files.item(counter).name

each iteration increasing the value of counter. This feels a little dirty to me though. I wish I could have access to a fileObj variable inside of the S3.upload invocation.