我正在为Google文档开发delphi api,并且很难让上传工作。我正在关注Google的开发指南here,根据我的理解,该过程应该是这样的:
https://docs.google.com/feeds/upload/create-session/default/private/full/?access_token=my_access_token&v=3&convert=false
发出POST请求:X-Upload-Content-Type
和X-Upload-Content-Length
200 OK
回复,其中包含Location
标题Location
标头发出PUT请求,标头Content-Type
设置为我在步骤1中设置为X-Upload-Content-Type
的标头,标头Content-Range
设置为类似这个:bytes 0-524287/2097152
和正文中的第一个512kb数据308 Resume Incomplete
标题Location
响应
201 Created
响应,其中包含描述我上传文件的xml数据包括第3步在内的所有内容都可以正常运行。事情发生在第4步,事情开始出错了。
最令我困惑的一件事是第4步的响应不包含Location
标头。我想这意味着我应该将下一个请求发送到同一个url,但这导致我得到504错误。我用fiddler尝试了整个过程只是为了看看它是否是delphi代码,我缺乏理解,或谷歌正在做的事情。
以下是我使用fiddler发送和接收的请求和响应:
POST https://docs.google.com/feeds/upload/create-session/default/private/full/?access_token=my_access_token&v=3&convert=false HTTP/1.1
Content-Type: application/x-www-form-urlencoded
X-Upload-Content-Type: application/octet-stream
X-Upload-Content-Length: 2097152
Content-Length: 0
Host: docs.google.com
HTTP/1.1 200 OK
Server: HTTP Upload Server Built on May 16 2012 12:03:24 (1337195004)
Location: https://docs.google.com/feeds/upload/create-session/default/private/full/?access_token=my_access_token&v=3&convert=false&upload_id=AEnB2Ur9-9VxMSI6kaFzbybY2qiyzK6kVoKzcZ6Yo02H8Ni4FlQFl_N06DdjZXzp3vSjOPH3CEb_4vDlKZp7VlC0hxpkypzlKg
Date: Tue, 22 May 2012 16:53:27 GMT
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate
Content-Length: 0
Content-Type: text/html
PUT https://docs.google.com/feeds/upload/create-session/default/private/full/?access_token=my_access_token&v=3&convert=false&upload_id=AEnB2Ur9-9VxMSI6kaFzbybY2qiyzK6kVoKzcZ6Yo02H8Ni4FlQFl_N06DdjZXzp3vSjOPH3CEb_4vDlKZp7VlC0hxpkypzlKg HTTP/1.1
Content-Type: application/octet-stream
Content-Length: 524288
Content-Range: bytes 0-524287/2097152
Host: docs.google.com
[first 512kb of data here]
HTTP/1.1 308 Resume Incomplete
Server: HTTP Upload Server Built on May 16 2012 12:03:24 (1337195004)
Range: bytes=0-524287
X-Range-MD5: bd9d4ee7afa24b7da0e685f05b5f1f44
Date: Tue, 22 May 2012 16:54:29 GMT
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate
Content-Length: 0
Content-Type: text/html
PUT https://docs.google.com/feeds/upload/create-session/default/private/full/?access_token=my_access_token&v=3&convert=false&upload_id=AEnB2Ur9-9VxMSI6kaFzbybY2qiyzK6kVoKzcZ6Yo02H8Ni4FlQFl_N06DdjZXzp3vSjOPH3CEb_4vDlKZp7VlC0hxpkypzlKg HTTP/1.1
Content-Type: application/octet-stream
Content-Length: 524288
Content-Range: bytes 524288-1048575/2097152
Host: docs.google.com
[next 512kb of data]
HTTP/1.1 504 Fiddler - Send Failure
Content-Type: text/html; charset=UTF-8
Connection: close
Timestamp: 10:54:14.056
我能做的唯一事情是能够说出一个事实,即它不是只是 delphi代码是错误的,因为我不认为它是谷歌,我我将不得不去做我不明白应该发生的事情。我错过了什么?
修改
我能够让上传工作,我不完全确定我做了什么不同,但文档有点误导。至少对我而言。当您发送PUT请求时,您没有获得新位置,只需继续上传到同一个位置即可。此外,当您完成上传时,201响应不包含实际的XML数据,而是具有Location
标题,指向您可以从中获取XML数据的位置。不是很大,但有点混乱。
答案 0 :(得分:2)