googleapis / nodejs-storage

Node.js client for Google Cloud Storage: unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
https://cloud.google.com/storage/
Apache License 2.0
891 stars 367 forks source link

SetMetadata is throwing not found error #2361

Closed vkclogituit closed 8 months ago

vkclogituit commented 8 months ago

Following block of code is given in the samples of this project.

And, I have create a object in the google cloud bucket and then I am trying to set the custom metadata for the same.

But this code block is throwing same error. ( Not Found )

const options = { ifMetagenerationMatch: 0, }; storage.bucket(bucketName) .file(filename) .setMetadata( { contentType: 'video/mp4', metadata: { description: 'file description...', modified: '1900-01-01', }, }, options ).then((data) => { console.log('COMPLETED) }).catch((error) => { console.log(error) });

Environment Details:

Steps to reproduce

  1. initialize storage object with serviceAccount
  2. run the given code and it will throw the not found error

Screenshot 2023-11-10 1035330000

ddelgrosso1 commented 8 months ago

Hi @vkclogituit I just tried the snippet you provided and I did not see any errors. Are you sure the object you are attempting to setMetadata on exists? Have you verified with a .exists() call to check?

vkclogituit commented 8 months ago

image

exists() returns true but still this code fails and getting not found error on setting the metadata.

ddelgrosso1 commented 8 months ago

Looking at the above code file.exists needs to either be provided a callback or awaited for the promise form. The documentation is here.

vkclogituit commented 8 months ago

I encountered an odd situation.

I uploaded video files ( mp4 ) to google bucket using preSigned Url and I have mentioned the same content type as video/mp4.

I can see the files on the bucket but those are not playing and showing the message as too large to view.

For those uploaded through preSigned url I could not able to set the metadata as file.exists returning false.

image

ddelgrosso1 commented 8 months ago

Would it be possible to see the code / an example of how you are uploading using a signed url?

vkclogituit commented 8 months ago

image

Here is my upload code

And I can see the upload going well from network logs image

vkclogituit commented 8 months ago

There were two issues, due to which I could not able to see the video playing and also not able to set the metadata. reason 1: treating folders also as bucket. instead of getting the bucket object by simply mention the bucket name, I was using the full path as bucket name ( except filename ) . Due to this file able to get placed correctly in right path but while setting the setMetada it was throwing the error.

Reason 2: from angular, I was uploading video file and setting the type as file instead of 'video'- due to that I could not able to play it back when I render the object .

So it is my mistake,

Thank you @ddelgrosso1 for guiding on this.