Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(183)

Unified Diff: Src/GoogleApis/Apis/[Media]/Download/MediaDownloader.cs

Issue 13480044: Issue 361: MediaDownloader can't download drive export list (which includes query parameters) (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: minor Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Src/GoogleApis/Apis/[Media]/Download/MediaDownloader.cs
===================================================================
--- a/Src/GoogleApis/Apis/[Media]/Download/MediaDownloader.cs
b/Src/GoogleApis/Apis/[Media]/Download/MediaDownloader.cs
@@ -15,6 15,7 @@
*/
using System;
using System.Linq;
using System.IO;
using System.Net.Http.Headers;
using System.Threading;
@@ -189,7 190,26 @@
throw new ArgumentException("stream doesn't support write operations");
}
- var builder = new RequestBuilder() { BaseUri = new Uri(url) };
RequestBuilder builder = null;
var uri = new Uri(url);
if (string.IsNullOrEmpty(uri.Query))
{
builder = new RequestBuilder() { BaseUri = new Uri(url) };
}
else
{
builder = new RequestBuilder() { BaseUri = new Uri(url.Substring(0, url.IndexOf("?"))) };
// remove '?' at the beginning
var query = uri.Query.Substring(1);
var pairs = from parameter in query.Split('&')
select parameter.Split('=');
// add each query parameter. each pair contains the key [0] and then its value [1]
foreach (var p in pairs)
{
builder.AddParameter(RequestParameterType.Query, p[0], p[1]);
}
}
builder.AddParameter(RequestParameterType.Query, "alt", "media");
long currentRequestFirstBytePos = 0;
@@ -219,8 239,20 @@
// read the headers and check if all the media content was already downloaded
var contentRange = response.Content.Headers.ContentRange;
- currentRequestFirstBytePos = contentRange.To.Value 1;
- long mediaContentLength = contentRange.Length.Value;
long mediaContentLength;
if (contentRange == null)
{
// content range is null when the server doesn't adhere the media download protocol, in
// that case we got all the media in one chunk
currentRequestFirstBytePos = mediaContentLength =
response.Content.Headers.ContentLength.Value;
}
else
{
currentRequestFirstBytePos = contentRange.To.Value 1;
mediaContentLength = contentRange.Length.Value;
}
if (currentRequestFirstBytePos == mediaContentLength)
{

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b