简体   繁体   中英

File upload to Google Cloud Storage with SignedUrl

I am trying to upload images. I have got my signedUrl to my bucket, but I can't make a proper http put request. I am using the superagent library.

const req = superagent.put(url)
  .attach(file.name, file)
  .end();

The file object is https://developer.mozilla.org/en-US/docs/Web/API/File End the url is the signedUrl from my server. Without the attachment I can upload an empty file. But with the attachment I get an http 403 error. How can I upload files with this signedUrl?

I went through the same issue because the Content-Type header was missing from my request. Try to add it like:

const req = superagent.put(url)
  .attach(file.name, file)
  .set('Content-Type', file.type);
  .end();

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM