Gabriel
Gabriel

Reputation: 862

Attempt to copy an object and set ACL fails

Using full control access and being the owner of the bucket and the object, a request of the following form:

POST https://www.googleapis.com/storage/v1beta2/b/mybucket/o/myobject/copyTo/b/mybucket/o/copiedobject?key={YOUR_API_KEY}

Content-Type:  application/json
X-JavaScript-User-Agent:  Google APIs Explorer

{
    "acl": [
        {
            "role": "READER",
            "entity": "allUsers"
        }
    ]
}

fails with the following response:

{
    "error": {
        "errors": [
            {
                "domain": "global",
                "reason": "required",
                "message": "Required"
            }
         ],
         "code": 400,
         "message": "Required"
    }
}

Uploading a new object with the same ACL works. Copying an object without setting ACL and subsequently adding the ACL also works.

Is the problem on my end or the API?

Upvotes: 1

Views: 179

Answers (1)

Travis Hobrla
Travis Hobrla

Reputation: 5511

Because the copy operation uses POST (not a PATCH), if you provide any metadata values, you have to provide a valid object resource for the destination object. That means the object resource you send needs to include all of the required fields, even if you're not changing them from the source.

Unfortunately, the documentation is unclear about which fields are required, and the error message is also unhelpful.

Try filling in the "name", "bucket", and "contentType" fields in addition to the ACL, and it should work.

Upvotes: 3

Related Questions