ユーザーに Google ドキュメントの統合を提供する PHP アプリケーションがあり、ファイルをユーザーのドキュメント アカウントに直接アップロードする機能を追加しようとしています (要件が単純で、この 1 つの機能のためだけに Zend Framework を台無しにしたくありません)。
https://developers.google.com/google-apps/documents-list/#uploading_a_new_document_or_file_with_content_onlyおよび https://developers.google.com/gdata/docs/resumable_uploadの指示に従っていますが、うまくいっているようです2 番目のチャンクを送信しようとするまでは OK です。この時点で、サーバーから常に 503 Service Unavailable 応答を受け取ります。
イベントの完全なシーケンスは次のとおりです。
1) 次のヘッダーを含む POST をアップロード URI に送信します。
Host: docs.google.com
GData-Version: 3.0
Authorization: Bearer (token removed for security reasons, but it's there and correct)
Content-Length: 0
Slug: gmk_google_upload_test.txt
X-Upload-Content-Type: text/plain
X-Upload-Content-Length: 2652
サーバーは次のように応答します。
HTTP/1.1 200 OK
Server: HTTP Upload Server Built on Jul 30 2012 11:18:04 (1343672284)
Location: https://docs.google.com/feeds/upload/create-session/default/private/full?convert=false&upload_id=AEnB2Uoa4ba2XrKG58GU3uTSzKUKsQu_NfOUvyYDqW6iXwmHgBPiJsi1fg-RhxMVT7jAfd1o73fUtBaaZ1uLkwNwzT04NxQbuQ
Date: Tue, 31 Jul 2012 16:00:13 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; charset=UTF-8
ここまでは順調ですね。
2) 次のヘッダーを使用して、最初のチャンク (512 バイト) を応答から URL に PUT します。
Host: docs.google.com
Content-Length: 512
Content-Type: text/plain
Content-Range: bytes 0-511/2652
サーバーは次のように応答します。
HTTP/1.1 308 Resume Incomplete
Server: HTTP Upload Server Built on Jul 30 2012 11:18:04 (1343672284)
Date: Tue, 31 Jul 2012 16:00:14 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; charset=UTF-8
ドキュメントに記載されているように、サーバーから Range ヘッダーが返されないため、これが問題の始まりである可能性があります。ただし、308 Resume Incomplete 応答を取得するには、何かが機能している必要があるようです。
3) 次のチャンクの (と思う) 正しいヘッダーと範囲情報を使用して次のチャンクを送信する場合:
Host: docs.google.com
Content-Length: 512
Content-Type: text/plain
Content-Range: bytes 512-1023/2652
私はいつもサーバーからこの応答を受け取ります:
HTTP/1.1 503 Service Unavailable
Server: HTTP Upload Server Built on Jul 30 2012 11:18:04 (1343672284)
Date: Tue, 31 Jul 2012 16:00:14 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; charset=UTF-8
さまざまな種類のファイル、チャンク サイズなどを試しましたが、常に同じ結果が得られます。奇妙なことに、サーバーが受信したバイト数を取得しようとするリクエストを送信すると (上記のドキュメント リンクに従って):
PUT <upload_uri> HTTP/1.1
Host: docs.google.com
Content-Length: 0
Content-Range: bytes */100
308 Resume Incomplete 応答が返されますが (予想どおり)、Range ヘッダーはまだありません。きっとどこかでバカなことをしているのだろうが、壁に頭をぶつけていて見えない。