Megabytemb / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

ResumeableUploader.InsertAsync 411 Length Required #583

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Use (InsertAsync(Authenticator, Uri, Stream, String, String, Object))
2.Server returns a 411 length required error

What version of the product are you using? On what operating system?
Latest from SVN. Win 7 x64.

Please provide any additional information below.
Inspecting using fiddler request is:

POST http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads 
HTTP/1.1
X-GData-Key: <removed>
Authorization: GoogleLogin auth=<removed>
Slug: 2012-04-19_210713401.mp4
X-Upload-Content-Type: video/mp4
X-Upload-Content-Length: 317500215
Host: uploads.gdata.youtube.com
Connection: Keep-Alive

Compared to a Request using (InsertAsync(Authenticator, AbstractEntry, Object))

POST http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads 
HTTP/1.1
X-GData-Key: key=<removed>
Authorization: GoogleLogin auth=<removed>
Slug: 2012-04-19_210713401.mp4
X-Upload-Content-Type: video/mp4
X-Upload-Content-Length: 317500215
GData-Version: 2.0
Host: uploads.gdata.youtube.com
Content-Type: application/atom+xml; charset=UTF-8
Content-Length: 573

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" 
xmlns:gd="http://schemas.google.com/g/2005">
  <media:group xmlns:media="http://search.yahoo.com/mrss/">
    <media:title>2012-04-19_210713401</media:title>
    <media:description />
    <media:keywords />
    <media:category>NONE</media:category>
  </media:group>
  <title type="text">2012-04-19_210713401</title>
  <link href="http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads" rel="http://schemas.google.com/g/2005#resumable-create-media" />
</entry>

Original issue reported on code.google.com by earwax...@gmail.com on 20 Apr 2012 at 5:03

GoogleCodeExporter commented 9 years ago
Forgot to add error message...

System.Net.WebException: The remote server returned an error: (411) Length 
Required.
   at System.Net.HttpWebRequest.GetResponse()
   at Google.GData.Client.ResumableUpload.ResumableUploader.InitiateUpload(Uri resumableUploadUri, Authenticator authentication, String contentType, String slug, Int64 contentLength, String httpMethod) in C:\YT SDK\clients\cs\src\core\resumableupload.cs:line 619
   at Google.GData.Client.ResumableUpload.ResumableUploader.InitiateUpload(Uri resumableUploadUri, Authenticator authentication, String contentType, String slug, Int64 contentLength) in C:\YT SDK\clients\cs\src\core\resumableupload.cs:line 600
   at Google.GData.Client.ResumableUpload.ResumableUploader.Insert(Authenticator authentication, Uri resumableUploadUri, Stream payload, String contentType, String slug, AsyncData data) in C:\YT SDK\clients\cs\src\core\resumableupload.cs:line 202
   at Google.GData.Client.ResumableUpload.ResumableUploader.AsyncInsertWorker(AsyncResumableUploadData data, AsyncOperation asyncOp, SendOrPostCallback completionMethodDelegate) in C:\YT SDK\clients\cs\src\core\resumableupload.cs:line 274 -

Original comment by earwax...@gmail.com on 20 Apr 2012 at 5:11

GoogleCodeExporter commented 9 years ago
I have hacked a away around this by forcing the content length to 0 as follows 
(starting line 603 of resumableupload.cs). The issue is now solved for me and I 
can upload.

        /// <summary>
        /// retrieves the resumable URI for the rest of the operation. This will initiate the 
        /// communication with resumable upload server by posting against the starting URI
        /// </summary>
        /// <param name="resumableUploadUri"></param>
        /// <param name="authentication"></param>
        /// <param name="entry"></param>
        /// <returns>The uri to be used for the rest of the operation</returns>
        public Uri InitiateUpload(Uri resumableUploadUri, Authenticator authentication, string contentType, string slug, long contentLength, string httpMethod) {
            HttpWebRequest request = PrepareRequest(resumableUploadUri,
                authentication,
                slug,
                contentType,
                contentLength,
                httpMethod);

            // Zero the content length
            request.ContentLength = 0;

            WebResponse response = request.GetResponse();
            return new Uri(response.Headers["Location"]);
        }

Original comment by earwax...@gmail.com on 20 Apr 2012 at 5:57

GoogleCodeExporter commented 9 years ago
Thanks for reporting the bug and for the quick fix, I committed your patch in 
rev. 1174:

http://code.google.com/p/google-gdata/source/detail?r=1174

Original comment by ccherub...@google.com on 20 Apr 2012 at 8:41

GoogleCodeExporter commented 9 years ago
I ran into the same issue but with the normal Insert method. I used this 
overload:
    public TEntry Insert<TEntry>(Uri feedUri, TEntry entry) where TEntry : AtomEntry;

I looked into the problem and have fixed it by adding the following line to 
google-gdata\clients\cs\src\core\request.cs (line 525):
    web.ContentLength = this.ContentLength;

That function creates a Request object based on the GDataRequest object. When 
doing that it copies the properties which both classes have. It seems that the 
ContentLength property was just forgotten.

@ccherubino, can you commit this patch?

Original comment by mark%lag...@gtempaccount.com on 3 May 2012 at 2:19

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the patch, Mark.
I'm going to test it as soon as possible, but I must be extra careful as the 
method you are changing, EnsureWebRequest(), is used by all APIs.

Original comment by ccherub...@google.com on 3 May 2012 at 10:19