Answered by:
Downloading Video using HTTPClient

Question
-
Hi All,
I am trying to download a video from a URL using a HTTPClient.
HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(videoURL); byte[] img = response.Content.ReadAsByteArray(); StorageFile file = await appData.LocalFolder.CreateFileAsync(contentName + ".MP4"); Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite); IOutputStream output = stream.GetOutputStreamAt(0); DataWriter writer = new DataWriter(output); writer.WriteBytes(img); await writer.StoreAsync(); output.FlushAsync().Start();
When i use this code for a jpg file download it works seamlessly but when i try to access the MP4 file it's not happening.
Anything i have to do in the mobile to get this going?Thanks in advance.
Regards Biju S Melayil- Edited by Biju S Melayil Thursday, November 10, 2011 11:53 AM Change in heading
Thursday, November 10, 2011 11:53 AM
Answers
-
Hi Biju,
There is a limit to the buffer size (this value is in bytes). http://msdn.microsoft.com/en-us/library/windows/apps/system.net.http.httpclienthandler.maxrequestcontentbuffersize(v=VS.110).aspx
You should be able to simply increase the buffer size to download your video.
-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, November 11, 2011 7:13 PM
- Marked as answer by Biju S Melayil Friday, November 11, 2011 7:19 PM
Friday, November 11, 2011 7:12 PMModerator
All replies
-
What is the problem you are running into? What is not happening? Are you getting an error while the code is running? Is the file not saving out at all? Is it saving out incorrectly? Is it saving out but you can't launch it?
--Rob
Thursday, November 10, 2011 7:47 PMModerator -
Hi Rob,
after this line of execution the application is giving me no response.
HttpResponseMessage response = await client.GetAsync(videoURL);
The download hasn't happened. the file we were trying to download is around 670KB.
Regards Biju S MelayilFriday, November 11, 2011 1:58 AM -
Hi Biju,
There is a limit to the buffer size (this value is in bytes). http://msdn.microsoft.com/en-us/library/windows/apps/system.net.http.httpclienthandler.maxrequestcontentbuffersize(v=VS.110).aspx
You should be able to simply increase the buffer size to download your video.
-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, November 11, 2011 7:13 PM
- Marked as answer by Biju S Melayil Friday, November 11, 2011 7:19 PM
Friday, November 11, 2011 7:12 PMModerator