Meteor-files: onAfterUpload is not getting called

Created on 28 Nov 2016  路  12Comments  路  Source: veliovgroup/Meteor-Files

how to implement onAfterUpload config function

but no such event occurs once the file uploaded successfully. I need to generate a thumbnail of the image once the image gets uploaded. I'm trying to use onAfterUpload event function, but it is not getting called at anytime. same with 'onBeforeUpload' on the server side.

    export const Attachments = new FilesCollection({
      collectionName: 'uploads',
      allowClientCode: false,
      onBeforeUpload: function (file) {
        console.log(file)
        // Allow upload files under 10MB
        if (file.size <= 10485760) {
          return true;
        } else {
          return 'Please upload image, with size equal or less than 10MB';
        }
      },
      downloadRoute: 'cdn/storage/uploads',
      storagePath: '/app/uploads',
      onAfterUpload: function(fileRef) {
        console.log("on After upload \n",fileRef)
      },
      public: true,
    });
question

All 12 comments

PS: I'm uploading file via http upload method.

@dr-dimitru if you can, please tell me why the issue like this, em not seeing if any one faces this issue. It is because of http upload?

Hello @ankibalyan ,

Sorry for delayed response.
I've tested your config on my end (via DDP and HTTP), onAfterUpload is always called.

Have you tried event model? Like:

Attachments.on('afterUpload', function (fileRef) {
  console.log("on After upload \n", fileRef);
});

Hello @ankibalyan ,

Is this issue still exists on your end?

Sorry for delayed response.
I've started working on couple of other features of the app, I'm handling this part in my http request now, instead of onAfterUpload which I don't think is fine place, just a quick fix around.

Is this 'onAfterUpload' a client side function? Or, this can be called on the server side, I was trying this on server side.

Server only

okay! I'll try this out in brand new sample app on git, and let you know if this works for me.

@dr-dimitru I've retried implementing file upload, here is sample app. I'm still not getting call on onBeforeUpload and afterUpload. Don't know what's wrong in my implementation.

Hi @ankibalyan ,

I've checked your code. Now I see why it's not called - you're using 3rd party (not internal) upload.
So, to trigger onAfterUpload here you need to add proceedAfterUpload fourth argument

  1. Note only onAfterUpload will be called in this case
  2. here use "hook" (a.k.a. callback) style, not events. Example:
const Attachments = new FilesCollection({
  collectionName: 'uploads',
  allowClientCode: false,
  downloadRoute: 'cdn/storage/uploads',
  storagePath: 'uploads',
  public: true,
  onBeforeUpload() { /*...*/ },
});

Thanks @dr-dimitru, It works, even with event style.
a lilttle doubt, is "3rd party upload" you mean to http REST API upload?
is the same reason valid to onBeforeUpload method as well for not getting called, and we should perform such input validations input like file size or file type here in commented lines of code.

It works, even with event style.

There is no such event onBeforeUpload nor beforeUpload, it's a hook/callback which expects to return Boolean value

a lilttle doubt, is "3rd party upload" you mean to http REST API upload?

Yes, it's not internal method of Meteor-Files package

perform such input validations input like file size or file type here in commented lines of code.

Yes, this will work as long as you send solid file (not by chunks).

Hope that helps

It works, even with event style.

There is no such event onBeforeUpload nor beforeUpload, it's a hook/callback which expects to return Boolean value

This works for the afterUpload hook (not event) on Attachments FilesCollection.

yes, It helped. Thanks a lot, I'm closing this issue :)

Was this page helpful?
0 / 5 - 0 ratings