Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Unable to Insert object to google cloud storage

Hi, I am able to get data from my bucket using postman. But not with uploading to my bucket. I have followed both simple and multipart upload but none works, even when I try with OAuth 2.0 Playground. The error message does not make sense as I followed the documentation and supplied the Authentication. 

Request Multipart:

POST /upload/storage/v1/b/[BucketName]/20230907/o?uploadType=multipart HTTP/1.1
Host: www.storage.googleapis.com
Content-length: 522564
Content-type: multipart/related; boundary="===============2358174219149564973=="
Authorization: Bearer [AccessToken]
--===============2358174219149564973==
Content-type: application/json

{"name":"file1.jpg"}
--===============2358174219149564973==
Content-type: image/png

[PNG FILE]

--===============2358174219149564973==--

Response Multipart:

HTTP/1.1 400 Bad Request
Content-length: 224
Vary: Origin
Server: UploadServer
X-guploader-uploadid: ADPycduaV61OxD9WV22MQ6N_A8u81I_HTeGs-uxSCulwiKDPvUIVgMGVNF8fBHEZp6lPFjNrFID1AqvS_gAXglnstW5TqqegQImD
Date: Thu, 07 Sep 2023 09:39:45 GMT
Alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Content-type: application/xml; charset=UTF-8

<?
xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidAuthentication</Code><Message>The provided authentication header is invalid.</Message><Details>Cannot use OAuth Authorization header with form POST.</Details></Error>

Request Simple:

POST /upload/storage/v1/b/[BucketName]/20230907/o?uploadType=media&name=file1.png HTTP/1.1
Host: www.storage.googleapis.com
Content-length: 522366
Content-type: image/png
Authorization: Bearer [AccessToken]

[IMAGE FILE]

Response Simple:

HTTP/1.1 401 Unauthorized
Content-length: 131
Vary: Origin
Server: UploadServer
X-guploader-uploadid: ADPycdvHc8xUeyTm5NnvvQVn5aLTvYwh8ETQrA_DAQA2tKLlMaYoitV2L0q4m6Hm0PF-rRP8kCFivTAYXVFLVaFFZzn_L44PeYBF
Date: Thu, 07 Sep 2023 09:50:50 GMT
Alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Content-type: application/xml; charset=UTF-8
Www-authenticate: Bearer realm="https://accounts.google.com/", error="invalid_token"

<?xml version='1.0' encoding='UTF-8'?><Error><Code>AuthenticationRequired</Code><Message>Authentication required.</Message></Error>
Solved Solved
1 1 2,014
1 ACCEPTED SOLUTION

Nevermind, I am now able to insert new object. After comparing with download request, I found that I used https://storage.googleapis.com as base url for upload, rather than https://googleapis.com. The url stated in official documentation uses storage in front of googleapis, so I followed it without thinking it is the issue.

View solution in original post

1 REPLY 1

Nevermind, I am now able to insert new object. After comparing with download request, I found that I used https://storage.googleapis.com as base url for upload, rather than https://googleapis.com. The url stated in official documentation uses storage in front of googleapis, so I followed it without thinking it is the issue.