elixir-google-api icon indicating copy to clipboard operation
elixir-google-api copied to clipboard

Problem copying / rewriting objects via Storage API.

Open harmon25 opened this issue 5 years ago • 3 comments

Struggled a bit trying to copy/rename an object with the existing elixir API.

 GoogleApi.Storage.V1.Api.Objects.storage_objects_rewrite(conn, src_bkt, src_obj, dest_bucket, dest_obj)
 GoogleApi.Storage.V1.Api.Objects.storage_objects_copy(conn, src_bkt, src_obj, dest_bucket, dest_obj)

Calling them as shown above always resulted in the following error:

{
  "error": {
    "code": 400,
    "message": "Unsupported content with type: application/octet-stream",
    "errors": [
      {
        "message": "Unsupported content with type: application/octet-stream",
        "domain": "global",
        "reason": "badContent"
      }
    ]
  }
}

I was able to work around by issuing a raw Tesla call:

    Tesla.post(
      "https://storage.googleapis.com/storage/v1/b/#{bucket}/o/#{URI.encode_www_form(old_key)}/rewriteTo/b/#{
        bucket
      }/o/#{URI.encode_www_form(new_key)}",
      "",
      headers: [
        {"authorization", "Bearer #{token}"},
        {"content-type", "application/json; charset=UTF-8"}
      ]
    )

The only difference between the manual call - and the library call is the inclusion of the content-type header in my own request.

Anyone else experience this? Am I misssing something?

Think because the body is empty, Tesla cannot infer content type - so it has to be manually included...

harmon25 avatar Jul 14 '20 19:07 harmon25

Have not been able to reproduce this. It's possible a change to Tesla (I am using 1.4.0), or a change to the backend behavior, has fixed this in the meantime. Are you still observing this issue?

dazuma avatar Mar 11 '21 20:03 dazuma

It doesn't work for me either. It happens when I'm coping jpg.

google_api_storage v0.29.0 tesla 1.4.2

Another issue related to copy: https://github.com/googleapis/elixir-google-api/issues/8009

ndan avatar Jul 30 '21 11:07 ndan

I'm also getting this when configuring with:

config :tesla, adapter: Tesla.Adapter.Hackney

Works fine with the default tesla adapter.

davidye avatar Oct 14 '21 23:10 davidye