jalik/meteor-jalik-ufs

How to resolve when copy file finished?

Opened this issue · 0 comments

How are you.
I am uploading image and copy it to thumbnails holder.
I added thumbnail url to main image collection so that I can load thumbnail instead of big img.
Now it working correctly, it upload main image and copy to thumbnail holder, and set thumbnail url to image collection correctly.
But it always return image collection without thumbnail url field.
This is what I have done. I run this function to upload image and copy it to thumbnail holder

return new Promise((resolve, reject) => {
// pick from an object only: name, type and size
const file = {
name: data.name,
type: data.type,
size: data.size,
};

const upload = new UploadFS.Uploader({
  data,
  file,
  store: ImagesStore,
  onError: reject,
  onComplete: resolve .  // here! when completed it returns image collection without thumb url
                                        // but if check db, it saves thumb url correctly.
});

upload.start();

});

And this is the main uploading and copy part.

const Thumbnail320Store = new UploadFS.store.Local({
...
onFinishUpload(file) {
Images.update({_id: file.originalId}, {$set: {thumb320Url: file.url}});
},
...
});
ImagesStore = new UploadFS.store.Local({
...
copyTo: [
Thumbnail320Store
],
...
});

Thanks