1

I am trying to resume an upload from google drive, I have the id of the file when I close the connection I make this session after the Internet is connected again:

var request = (HttpWebRequest)WebRequest.Create(fileUri);
            request.Method = "PUT";
            request.ContentLength = 0;
            request.Headers.Add("Content-Range", "bytes */" + FileByteArray.Length);
            try
            {
                var response = request.GetResponse();
            }
            catch (WebException e)
            {
               fileRange = e.Response.Headers.Get("Range");
            }

        }

I am not getting the Range header, why is that?

1 Answers1

2

Content-Range indicates which range of the original entity is contained in the body of either a request (like your PUT request) or a 206 partial response. Range is set by the client not the server in order to request a sub-range. I would assume that the server you are talking to will not respond with the uploaded chunk, so a Content-Range (and Range in no case) will not be present as a response header.

In your code snippet the actual upload range is missing for Content-Range (see the updated HTTP RFC). It has to have the form of:

Content-Range: bytes 42-1233/1234

which means: upload byte 42-1233 of an entity whose total size is 1234 byte.

Or when the complete length is unknown:

 Content-Range: bytes 42-1233/*

So remove the check for the Range header and specify the complete upload range and you should be fine.

Community
  • 1
  • 1
DivineTraube
  • 691
  • 5
  • 9
  • Just needed to add on my upload request uploadReq.AddRange(FileByteArray.Length.ToString(), 0, FileByteArray.Length - 1); And it worked, thanks – Borislav Nikolaev Nov 08 '16 at 10:12