Hi, I am uploading my text editor (Quil Editor) files using React and Meteor-Files.
But I do not know exactly how to get the link after uploading and put it in the editor.
Do I have to subscribe to get the link to that file after upload?
And if so. Is there a way to subscribe to that file right away?
Note that I have to subscribe to this file in such a way that I can get the file link in the same method (UploadImage)
Because if I subscribe to it as a withTracker, this method will not be rendered again so that I can get the link to that file.
I asked here too and sied more :
https://forums.meteor.com/t/how-to-get-link-file-after-upload-in-meteor-files/54432
Hello @Saeed-Bahrami ,
I updated .link() method documentation, hope now this method usage will be more straightforward.
TL;TR; You have next options:
fileRef the copy of the file object from MongoDB record; Using this record you can do FilesCollection#link(fileRef)FilesCollection#find().link()Feel free to close it in case if the issue is solved on your end.
@dr-dimitru
I'm sorry, but I still did not understand correctly.
As I realized, the following code should work, and without subscribing, I should get the link after uploading.
const upload = ImgCollection.insert({
file: Img,
streams: 'dynamic',
chunkSize: 'dynamic'
}, false);
console.log(upload);
upload.start();
const file = ImgCollection.findOne({_id:`${upload.config.fileId}`});
console.log(file.link());
As I realized, the following code should work, and without subscribing, I should get the link after uploading.
Listen for end event on the Client as in the example link from my message above. Something like that:
const upload = ImgCollection.insert({
file: img
}, false).on('end', function (error, fileObj) {
// get link in here
console.log(ImgCollection.link(fileObj))
}).start();
upload.start();
@dr-dimitru
It was great, he answered.
Thank you for your prompt and accurate response
It was great, he answered.
yeah, he answered kk
@Saeed-Bahrami I'm glad this issue was quickly solved
Please support this project with:
@dr-dimitru Hello again.
I got the image link the same way, and save it in the database so I can display it later.
But after a while (I do not know exactly how many hours) the links expire and error 404 returns.
Do the links expire?
What method should we use to always display images?
@Saeeed-B it sounds to me that you ran into different issue described in our FAQ:
meteor reset.__ To keep your storage persistent during development use an absolute path outside of your project folder, e.g. /data directory.If it's not the case, I'll request more details
@Saeeed-B is this one solved o you end? You haven't replied since my comment
@dr-dimitru Hi, thank you for your help, I have to test Rahel.
I will definitely report if I see a problem
Thanks
Most helpful comment
@dr-dimitru
It was great, he answered.
Thank you for your prompt and accurate response