Calin Pavel
Calin Pavel

Reputation: 21

Google Storage Resumable upload fails with CORS error

I'm trying to:

  1. generate on the server side a resumable upload URL using either XML API or JSON API -> URL is generated correct and can be used
  2. return that URL to browser and force upload of a file to that URL using JavaScript / jQuery.
  3. When doing the call, since is a CORS request:

a) first a preflight request is sent and get back a response 200, which includes header: access-control-allow-origin with the correct host name

b) next, the upload request is sent to Google storage, upload is done correct and get back the response (e.g including JSON with the upload details).

BUT the response does not include header: access-control-allow-origin and because of that browser complains: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.googleapis.com/upload/storage/v1/b/test-bucket/o?uploadType=resumable&upload_id=AEnB2UoTmA9ul. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

To solve this problem some articles suggest:

Upvotes: 2

Views: 915

Answers (1)

Calin Pavel
Calin Pavel

Reputation: 21

Yes, I solved it - the problem was that Java does not allow to send / set Origin header with a custom value. So, even if I set Origin value - it was not sent.

To solve it, have to configure sun.net.http.allowRestrictedHeaders=true when starting Java process.

Upvotes: 0

Related Questions