tomitrescak/meteor-uploads

Subdirectory creation 'double slashes'

Opened this issue · 2 comments

Hello,

I'm enjoying using the clear API of your nice meteor-uploads module but I'm running into the following problem. The end result is working for me but I still think there might be some improvement in the way the subdirectories are working - or maybe it is because I am doing something wrong.

I have configured the UploadServer in such a way that I'm putting my uploaded images in subdirectory based on a variable called 'groupId'. Note that I add a '/' before and after my desired subDirectory in the code below. If I do not do this (running locally on OSX - El Capitan) the files get saved with prefixed filename - not in subdirectory.

server/init.js
if(Meteor.isServer) { Meteor.startup(function() { UploadServer.init({ tmpDir: process.env.PWD + '/.uploads/tmp', uploadDir: process.env.PWD + '/.uploads/', checkCreateDirectories: true, //create the directories for you finished: function(fileInfo, formFields) { fileInfo.groupId = formFields.groupId; fileInfo.teamId = formFields.teamId; }, getDirectory: function(fileInfo, formFields) { return "/"+formFields.groupId+"/"; } }); }); }

However, due to this, in the client side code the 'url' of fileInfo object looks like this (note 'double' slashes):
"http://localhost:3000/upload//xqoHGq6syrLjTuNb3//1458162890876-1139262283.jpg"

This does not lead to problems when fetching the file later - the browser compensates for the double slashes but still I think this is not a very 'nice' way of saving it in a Collection as I am doing in the code below:

custom callback in custom template
myCallbacks: function (){ var groupId = Router.current().params._id; return { formData: function() { return { teamId: Session.get("activeTeam"), groupId: groupId } }, finished: function(index, fileInfo, context) { // upload completed insert fileInfo into collection Meteor.call('insertUpload', fileInfo, function(error, result) { var data = { photoId: result }; submitEvent(data); }); } } }

Currently my workaround is as follows, its bad but works:

finished: function(index, fileInfo, context){
        fileInfo.path = fileInfo.path.replace("//", "/");
        fileInfo.url = fileInfo.url.replace("//", "/");
        //will mess up http://
}

Bad idea... don't bother

Nevermind, I seem to run into lots more issues.
Take a look at the solution in #220