Uploading video results in stream error
See original GitHub issueI’m trying to upload videos to Facebook using the methods in place as follows:
dynamic parameters = new ExpandoObject();
parameters.source = new fb.FacebookMediaObject { ContentType = mimeType, FileName = request.Filename }
.SetValue(ServiceCommon.Common.GetBytesFromStream(videoData).ToArray());
parameters.title = request.Title;
parameters.description = request.Description;
but when I do large videos (>~20mb), I get the following error consistently: Facebook upload failed: mimetype [video/mp4]System.Net.WebException: The request was aborted: The request was canceled. —> System.IO.IOException: Cannot close stream until all bytes are written. at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting) — End of inner exception stack trace — at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting) at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState) at System.Net.ConnectStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.Stream.Dispose() at Facebook.FacebookClient.Api(HttpMethod httpMethod, String path, Object parameters, Type resultType) at Facebook.FacebookClient.Post(String path, Object parameters) at CallSite.Target(Closure , CallSite , FacebookClient , String , Object ) at FacebookTransferService.Upload(FacebookUploadRequest request, Stream videoData)
Issue Analytics
- State:
- Created 11 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Changing from fb.Post(endpointUri, parameters); to Task t = fb.PostTaskAsync(endpointUri, parameters); t.Wait();
appears to have done the trick.
Thanks.
-----Original Message----- From: Prabir Shrestha [mailto:reply@reply.github.com] Sent: Thursday, July 12, 2012 11:40 PM To: bc3tech Subject: Re: [facebook-csharp-sdk] Uploading video results in stream error (#181)
For attachments (photo/video) upload it is highly recommended not to use byte array. Use FacebookMediaStream instead and use the async version
PostAsync
orPostTaskAsync
. You can find how to use FacebookMediaStream at http://csharpsdk.org/docs/making-asynchronous-requestsLet us know if it works then.
Reply to this email directly or view it on GitHub: https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/issues/181#issuecomment-6954555
Try setting
HttpWebRequest.Timeout = -1;
(or higher value) andHttpWebRequest. ReadWriteTimeout
to a higher value.This is an advanced option and will most likely be hidden from intellisense depending on your VS settings. You can learn about how to set it at http://stackoverflow.com/a/10931752/157260
You can use async in server side using IHttpAsyncHandler http://msdn.microsoft.com/en-us/library/system.web.ihttpasynchandler.aspx There are other options if you are using mvc.
I don’t consider this a bug but rather an excepted result.