Meteor-files: How to return error from onAfterUpload method to client

Created on 5 Nov 2017  路  8Comments  路  Source: veliovgroup/Meteor-Files

Hello!

I am using your package.
On client side, after I start upload I have handlers:

            uploadInstance.on('end', function (error, fileObj) 
            uploadInstance.on('error', function (error, fileObj)

And on server side I have method onAfterUpload - inside this method there is a case, when I wan't to return error to client and see it in parameter ERROR in its handles, but I don't know how to do this ans didn't found solution on your wiki

  • I tried to return false
  • I tried to return some text

Nothing of it I see on the client.

Thanks

.insert() (upload) question

All 8 comments

Hello @koblents ,

Not possible, as onAfterUpload is triggered asynchronously after upload is successfully finished.
Please describe your case in details, what are you trying to accomplish?

@koblents you can update file doc in onAfterUpload with status/error of the file processing.
On the client you can subscribe to file doc and observe changes to monitor after upload progress.
I used that approach to notify client when file processing (thumb creation + anti virus scanning) is completed.

+1 for method suggested by @vbelolapotkov
We use the same approach in our demo app, listening for generated thumbs availability, see code here, you can use any other property in the same way.

Hello @koblents ,

Have you solved it?

No, I didn't, because in my logic, if I have some error inside onAfterUpload - I immediately delete file and mongoDB row - and with it I don't know how to tell client about it.

@koblents inside onAfterUpload hook add deleted or error property, if any of those props exists on the file's record show error message and hide them. Then set Mongo's TTL Index, file's record will be automatically removed upon expiration. See this tutorial.

See similar approach used in our demo app and __very important comment__ here

Let me know if it helped you.

thanks @dr-dimitru I don't really like this solution, because it seems too complicated, can confuse users and also can reflect more issues.
But anyway I think we can close this issue - you gave me few solutions and if it will become critical for me, I will use one of them.

Thanks

Feel free to reopen it in case if the issue still persists on your end.

Please, support this project by:

Was this page helpful?
0 / 5 - 0 ratings