How do I get url from FS.Collection

        var imageId = '';
        FS.Utility.eachFile(event, function(file){
            Images.insert(file, function (err, fileObj){
                imageId = fileObj._id;
            });
        });
        console.log(imageId);

How do I get from a URL from fileObj or its id that I can use on img tags later? I want to store the url in another record. Do I need some sort of method on my server to get it after a upload? My upload works I see the files getting uploaded and some info is stored in my database but I don’t understand how to get a usable URL.

Figured it out:

console.log('/cfs/files/images/' + imageId + '/images?store=images');

images should be replaced with your own name for your FS system.

Its been awhile since I’ve worked with CollectionFS, but as far as I know file.url() should return the url. I think though that the object passed to the insert call back may not be an instance of FS.File so you might need to do that part manually if not.

FS.Utility.eachFile(event, function(file){
    Images.insert(file, function (err, fileObj){
        console.log(fileObj.url({store:"images"}));
           //OR if fileObj is not an instance of FS.file you can make it one.
        console.log(new FS.File(fileObj).url({store:"images"}));
    });
});
2 Likes