How to get link file after upload in Meteor Files

Hello friends, 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?

This is my code :

<input type="file" accept="image/*" onChange={this.UploadImage.bind(this)} />

 UploadImage= (e) => {
        e.preventDefault();

        if (e.currentTarget && e.currentTarget.files && e.currentTarget.files.length > 0) {
            const file = e.currentTarget.files[0];

            const upload = EditorImg.insert({
                file: file,
                streams: 'dynamic',
                chunkSize: 'dynamic'
              }, false);

            upload.on('start', function () {
                console.log(this);
              });

            upload.on('end', function (error, fileObj) {
            if (error) {
                alert(error);
            } else {
                alert('File "' + fileObj.name + '" successfully uploaded');
            }
            });
            upload.start();
            const FileId = upload.config.fileId ; // this is id of file doc      
        }
    };

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

Hello @saeeed,

I updated .link() method documentation, hope now this method usage will be more straightforward. Also answered on your original question at GitHub

1 Like