问题
I am trying to POST image to google cloud storage via multipart request using their JSON API, but I am receiving an error:
"code": 400,
"message": "Bucket is requester pays bucket but no user project provided."
HERE IS MY REQUEST:
POST /upload/storage/v1/b<my_bucket_here>/o?
uploadType=multipart&name=testPostman HTTP/1.1
Host: www.googleapis.com
Content-Length: 2139
Authorization: Bearer ya29.<my_token_here>
Cache-Control: no-cache
Postman-Token: 6fb40df7-3a0d-fda6-a94e-63365f594c9d
Content-Type: multipart/form-data; boundary=----
WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="data"; filename="profilephotos-
960x640.jpg"
Content-Type: image/jpeg
I tried going to my bucket, and project IS specified there. The only thing that looks strange is Lifecycle part, which is None, and when I click to change it, it opens a page Failed to open. This is so weird.
Can it be because I am not the owner, but an Admin of the project? Billing is enabled for the bucket. Please help! Spent 3 days for this already.
回答1:
The "requester pays" feature of Google Cloud Storage allows the owner of the bucket pays for the cost of storing the objects, but the users of the bucket to pay for the cost of using the bucket.
Once requester pays has been enabled, every request needs to specify which project is to be billed for that request. The only exceptions are:
- The caller is the owner of the bucket, or
- The caller has the
resourcemanager.projects.createBillingAssignment
permission for the bucket's project.
Otherwise, you'll need to explicitly specify a project to be billed by including the URL parameter userProject=myProjectId
. So, in your case, make this change to the URL you're invoking:
POST /upload/storage/v1/b/o?userProject=YOUR-PROJECT&uploadType=multipart&name=testPostman
来源:https://stackoverflow.com/questions/47739741/bucket-is-requester-pays-bucket-but-no-user-project-provided