Resumable upload with PHP/cURL fails on second chunk.

1,009 views
Skip to first unread message

david David

unread,
Jun 8, 2011, 12:15:27 AM6/8/11
to google-docum...@googlegroups.com
Hello Guys,

For some reason my resumable upload fails to work and does not return the "Range:" header after sending the first chunk of data.

This are the headers I receive after submitting the first chunk: 
-----------------
First chunk request header:

PUT /feeds/upload/create-session/default/private/full?convert=false&upload_id=AEnB2UqJ68bpomEud6sFRrvR3bimDX5ofW4IOh82TeH0-x3TTKQMjF3YeMYjaxIoS-DHz5dgbi3jqWeJ_fphlB59NpXAcRrHBw
 HTTP/1.1
Host: docs.google.com
Content-Type: text/plain
Content-Length: 8
Content-Range: bytes 0-7/50
--
First chunk response header:

HTTP/1.1 308 Resume Incomplete
Server: Upload Server Built on May 13 2011 14:17:29 (1305321449)
Date: Thu, 02 Jun 2011 21:09:50 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
-----------------

If I continue sending the second chunk it just fails with the following header:
-----------------
Second chunk request header:

PUT /feeds/upload/create-session/default/private/full?convert=false&upload_id=AEnB2UqJ68bpomEud6sFRrvR3bimDX5ofW4IOh82TeH0-x3TTKQMjF3YeMYjaxIoS-DHz5dgbi3jqWeJ_fphlB59NpXAcRrHBw
 HTTP/1.1
Host: docs.google.com
Content-Type: text/plain
Content-Length: 8
Content-Range: bytes 8-15/50
--
Second chunk response header

HTTP/1.1 503 Service Unavailable
Server: Upload Server Built on May 13 2011 14:17:29 (1305321449)
Date: Thu, 02 Jun 2011 21:09:50 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
-----------

Here's my php code for sending the chunks:
$headers = array(
		"Content-Type: text/plain",
		"Content-Length: 8",
		"Content-Range: bytes 0-7/50",
		"Accept:"
		);					
			
//--Make the upload request
$ureq = curl_init();				
curl_setopt($ureq, CURLOPT_URL, $chunk_url);
curl_setopt($ureq, CURLOPT_RETURNTRANSFER, 1);			
curl_setopt($ureq, CURLOPT_CONNECTTIMEOUT, 30);			
curl_setopt($ureq, CURLOPT_HEADER, true);				
curl_setopt($ureq, CURLOPT_HTTPHEADER, $headers);				
curl_setopt($ureq, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ureq, CURLOPT_POSTFIELDS, $package);
													
//--Execute upload request
$response = curl_exec($ureq);
				
//--Get error
if(curl_errno($ureq)) 
	throw new Exception(curl_error($ureq));
				
echo $response;

Please let me know if you have any ideas,
Thank you!

Tri Gunadi

unread,
Jun 8, 2011, 5:14:09 AM6/8/11
to google-docum...@googlegroups.com
same here...
here's my log? 

[ Requesting upload url ]
request upload link for resumable upload
upload URL :https://docs.google.com/feeds/upload/create-session/default/private/full?convert=false
intializing upload


sending second chunk: error, returned 503. 
send another request to upload URL
PUT <upload_uri>
Content-Length: 0
Content-Range: bytes */100

returned, 308 without "Range" header,
so, continue upload from last range...
[ returned 503, kepp doing the last step ] 
there was a 503, trying to upload chunk to https://docs.google.com/feeds/upload/create-session/default/private/full?upload_id=AEnB2Ur0hOka7RTIGIb5B8L_-CE4SJ5b0RlovU3JKiOcN6ibxWWRZNQCz0GF5Nk7f5IF2l21Hrivyk0BDqyGE76pK73MPyuxAA
size: 256000-511999

[ Maximum execution time of 60 seconds exceeded ] 
Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\experiment\http_proxy.php on line 174

What's goin on?

Jens Lundberg

unread,
Jun 8, 2011, 6:24:23 AM6/8/11
to google-docum...@googlegroups.com
What's the size of the chunks?

It must be a size divedable by eight , like 786432 or like this:

int DEFAULT_CHUNK_SIZE = 10485760;

Regards
/Jens

Tri Gunadi

unread,
Jun 8, 2011, 6:38:32 AM6/8/11
to google-docum...@googlegroups.com
mine is 256.000 chars length so it's 256.000 Bytes

256000/8 = 32000

but i'm using the assumption that 1 string equals to 1 byte.
or am i doing anything wrong?

david David

unread,
Jun 8, 2011, 6:39:11 AM6/8/11
to google-docum...@googlegroups.com
Hi Jens,

I read before that the chunk size must be divedable by 8. In my tests I used 8 byte chunks and I also specified the length in the header:

Content-Length: 8
Content-Range: bytes 0-7/50

Regards,
David

david David

unread,
Jun 9, 2011, 2:51:11 PM6/9/11
to google-docum...@googlegroups.com
Hello, any updates on this issue?

Thank you,

David

Andrew Fields

unread,
Jun 9, 2011, 10:16:15 PM6/9/11
to google-docum...@googlegroups.com
According to the protocol spec chunk size is 256kbytes.

david David

unread,
Jun 10, 2011, 9:50:04 AM6/10/11
to google-docum...@googlegroups.com
You are extremely right. :) I found it myself after reading again carefully the documentation.

When using multiples of 256KB (262144bytes) it works like a charm. :)

Issue closed.

David

juji

unread,
Jun 11, 2011, 5:03:07 AM6/11/11
to google-docum...@googlegroups.com
ooo so there's my problem

ths :)
--
Regards,

Tri Rahmat Gunadi - JUJI
Ph 0813.1012.8924

Reply all
Reply to author
Forward
0 new messages