1

Here is the request and response

**Request URL:https://www.googleapis.com/upload/drive/v2/files/0B6B-RNrxsCu2S0xxSkZQUEQ3eDQ?uploadType=media**
Request Method:OPTIONS
Status Code:200 OK
Request Headersview source
:host:www.googleapis.com
:method:OPTIONS
:path:/upload/drive/v2/files/0B6B-RNrxsCu2S0xxSkZQUEQ3eDQ?uploadType=media
:scheme:https
:version:HTTP/1.1
accept:*/*
accept-encoding:gzip,deflate,sdch
accept-language:en-US,en;q=0.8,en-AU;q=0.6
access-control-request-headers:accept, content-type, authorization, upload-content-length, upload-content-type
access-control-request-method:PUT
origin:http://dev.example.co:8888
referer:http://dev.example.co:8888/app/drivecrud.html
user-agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36
Query String Parametersview sourceview URL encoded
uploadType:media

**Response Headersview source**
alternate-protocol:443:quic
cache-control:no-cache, no-store, max-age=0, must-revalidate
content-length:0
content-type:application/octet-stream
date:Fri, 18 Apr 2014 06:46:58 GMT
expires:Fri, 01 Jan 1990 00:00:00 GMT
pragma:no-cache
server:HTTP Upload Server Built on Apr 11 2014 13:30:54 (1397248254)
status:200 OK
version:HTTP/1.1

Fails with ...

OPTIONS https://www.googleapis.com/upload/drive/v2/files/0B6B-RNrxsCu2S0xxSkZQUEQ3eDQ?uploadType=media 
Origin http://dev.example.co:8888 is not allowed by Access-Control-Allow-Origin.

By way of confirmation that everything else seems OK...

  • I just created the file that I'm uploading content to, so it's not permissions
  • If I replace uploadType=media -> =multipart, then I can correctly create a new file with content.

So it feels like one of

  • I've mis-formed the request in some way
  • Drive bug

The Drive API is documented at https://developers.google.com/drive/web/manage-uploads#simple

so I'm asking, is my request not as specified by the API, or it is as specified and the API is broken.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • 1
    seems you have a crossdomain problem. see https://stackoverflow.com/questions/10143093/origin-is-not-allowed-by-access-control-allow-origin – sschrass Apr 21 '14 at 11:14
  • http://stackoverflow.com/questions/11617229/solved-does-https-www-googleapis-com-upload-drive-v2-files-really-support-co – TSK Apr 25 '14 at 21:44

1 Answers1

0

As people have commented: looks like a crossdomain problem.

I assume you are using javascript to make this request;

Basicly you're bumping into a security measure for preventing scripts from moving data from one site to another without you knowing it.

The easiest way I found to fix this, unless you can edit the headers at googleapis.com, is jQuery-File-Upload. It works cross domain :)

You could also make it a 'jsonp' dataRequest, which is meant for cross domain communication.


It can easily be fixed if you have control over the receiving/responding server by adding

Access-Control-Allow-Origin: * 

to the header. However you probably don't have the possibility to edit the headers of googleapis.com.


Sources: http://www.fbloggs.com/2010/07/09/how-to-access-cross-domain-data-with-ajax-using-jsonp-jquery-and-php/

Access-Control-Allow-Origin error sending a jQuery Post to Google API's

http://cypressnorth.com/programming/cross-domain-ajax-request-with-json-response-for-iefirefoxchrome-safari-jquery/

Community
  • 1
  • 1
  • Thx Andreas, but the question is specific to drive sdk. I want to know if (a) my request differs from the advertised upload request in some way that I haven't spotted, or (b) this is a bug in the Drive API. I've updated the question to be be more specific. – pinoyyid Apr 26 '14 at 03:14
  • @pinoyyid: your request is fine and API is also fine. The limitation is imposed by your language of choice and implementation. Basically, the upload will work from any client written in I.e. C#, Java, Perl, whatever else - as long as the code is not executed in browser. – Sergey Kudriavtsev Apr 26 '14 at 07:28
  • @pinoyyid Then I don't think I can be of much help. – Andreas Storvik Strauman Apr 26 '14 at 10:11
  • @SergeyKudriavtsev why does the upload work for a multipart, but fail for a simple upload? The CORS dialogue should be the same right? – pinoyyid Apr 26 '14 at 11:54