S3 icon indicating copy to clipboard operation
S3 copied to clipboard

Get file name of photo uploaded

Open ryanswapp opened this issue 9 years ago • 5 comments

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);
                    }
                });
            }
        });

ryanswapp avatar Jun 05 '15 23:06 ryanswapp

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.

Lepozepo avatar Jun 06 '15 01:06 Lepozepo

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

ryanswapp avatar Jun 06 '15 02:06 ryanswapp

That's something I could probably add on. I'll have a look tonight hopefully.

Lepozepo avatar Jun 06 '15 14:06 Lepozepo

That would be awesome, thanks!

ryanswapp avatar Jun 06 '15 14:06 ryanswapp

:+1:

andregoldstein avatar Oct 12 '15 10:10 andregoldstein