tomitrescak / meteor-uploads

MIT License
295 stars 41 forks source link

Feature Request: rename file with unique name #179

Closed MeKarina closed 8 years ago

MeKarina commented 8 years ago

Hello thank you for the great packages. I have request if you welcome

Case:

User 1 need to change her avatar. She upload image with the name image.jpg. User 1 able the change her avatar. User 2 also need to change her avatar. She upload image with the same name of User 1 (image.jpg). User 2 will get avatar of User 1 because image.jpg has already in Upload folder

What I thought is to use random package. But won't work

Meteor.startup(function () {
  UploadServer.init({
    tmpDir: '/Users/karina/cat/Uploads/tmp',
    uploadDir: '/Users/karina/cat/Uploads/',
    checkCreateDirectories: true,
    minFileSize: 10,
    maxFileSize: 1000000,
    getFileName: function(fileInfo, formData) {
      return Random.id();
    },
    finished: function(fileInfo, formData) {
      if (formData != null) {
        Meteor.users.update({_id:formData.userId}, { $set: { "profile.avatar":fileInfo.url }});
      }
    }
  })
});

thank You...