Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0.0-beta.6] fileObj._id on upload end ? #889

Open
ddaydd opened this issue May 6, 2024 · 16 comments
Open

[3.0.0-beta.6] fileObj._id on upload end ? #889

ddaydd opened this issue May 6, 2024 · 16 comments

Comments

@ddaydd
Copy link

ddaydd commented May 6, 2024

Hello,

with the 3.0.0-beta.6 version, how to retrieve the id?

      upload.on('end', function (error, fileObj) {
          console.log(fileObj._id); // undefined
    }

Thanks.

@dr-dimitru
Copy link
Member

@bratelefant @jankapunkt @harryadel do we have bug in beta/rc release?

@dr-dimitru
Copy link
Member

@ddaydd have you found a solution?

@ddaydd
Copy link
Author

ddaydd commented Jun 25, 2024

no, and I saw that findOne became findOneAsync but no insertAsync?

@dr-dimitru
Copy link
Member

dr-dimitru commented Jun 25, 2024

@ddaydd .insert is client only and only mimics .insert method of mongodb driver

@ddaydd
Copy link
Author

ddaydd commented Jun 26, 2024

thank you for motivating me...
I found the _id

...
let fileId;
upload.on('start', function () {
  fileId = this.config.fileId
});
...

@dr-dimitru
Copy link
Member

@ddaydd I'm sure it's available via this inside end event as well

@ddaydd
Copy link
Author

ddaydd commented Jul 1, 2024

Yes, i confirm, but I leave it open, this must at least be changed or documented. thanks.

@donstephan
Copy link

donstephan commented Jul 24, 2024

I'm seeing this on the client in the upload.on('end') callback. The resulting fileObj doesn't include a _id like it used to. Anyone else experiencing this?

Using ostrio:[email protected]

@donstephan
Copy link

Seems you need to access the fileId through the uploadInstance config element in ostrio:[email protected]

For example:

var uploadInstance = Images.insert({
  file: file,
  chunkSize: 'dynamic'
}, false);

uploadInstance.on('end', function () {
  console.log('File _id: ', uploadInstance.config.fileId);
});

uploadInstance.start();

@dr-dimitru
Copy link
Member

@donstephan

  1. Note: Do not rely on .fileId as to _id of the file as they may differ for obfuscation purposes (built-into this package)
  2. Have you checked file's details on this context?

@donstephan
Copy link

donstephan commented Jul 29, 2024

In the example I shared above there's no this context relevant to the file upload. This is strictly client side. The resulting fileObj doesn't have any _id on it like it used to.

The resulting this context doesn't contain a fileId. this.config.fileId is the only place a reference the fileId exists.

To clarify, even though I'm listening to the 'end' event, the fileId in the uploadInstance potentially isn't the resulting _id of the file per obfuscation (which is fair).

Is this related to this comment in the 3.0 PR? #884 (comment)

I can share a test if needed.

@bratelefant
Copy link

Ok, when I eventually started moving my full app to 3.0.1 I also can confirm this is a breaking change. I don't get a proper fileRef in the "uploaded" event listener callback; worked fine in 2.16. Trying to figure this out...

@timsun28
Copy link

timsun28 commented Aug 6, 2024

I'm having the same issue after updating to meteor 3.0 and using v3.0.0-beta.6.
I also found that the onUploaded hook doesn't work properly anymore. It doesn't return an error/fileObj and this is undefined and it also runs instantly after submitting. I'm not sure if this is intended, as it isn't very clear what is new in v3.

Running the following code:

const upload = ElementPhotos.insert(photoObject, false);
upload.on("end", function () {
    console.log({ thisInstance: this });
    console.log("File _id: ", upload.config.fileId);
});

The "this" instance contains some details about the file upload and the upload.config.fileId is a random string, but as dr-dimitru pointed out, this shouldn't be used for the required usage.

I also needed to update my s3 code to fix some issues, now that the collections are also using async functions like findOneAsync, updateAsync and removeAsync. This will also need to be updated in the types, or preferably have the types be added to the package so it wouldn't be necessary to update types manually.

@bratelefant
Copy link

Ok just pushed d573741
This should return the fileObj after it was inserted in the db on "end" and "uploaded" events on the client. Feel free to test and comment

@timsun28
Copy link

Just installed the package locally with your latest changes and can confirm that this fixed the issue. It now returns the expected object in both the end callback and the onUploaded that includes the _id of the newly inserted file/image and more.

Thank you for your support and hard work on upgrading this package!

@hluz
Copy link

hluz commented Sep 23, 2024

Ok just pushed d573741 This should return the fileObj after it was inserted in the db on "end" and "uploaded" events on the client. Feel free to test and comment

Any progress on this push?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants