.net - How to convert Video to byte Array in C# ( c sharp )? -


I am using c # .com compact framework 3.5 and I want to convert a video file to byte array So that I can upload it to the server

In the same way, I am uploading an image which is achieving success results ....

  HttpWebRequest request; Request.ContentType = "Image / JPEG"; Request.ContentLength = byteArray.Length; request. Method = "put"; ImageToByteArray (img) .CopyTo (Bytere, 0); (Stream request stream = request. Gaterequesteststream ()) using {requestStream.Write (Bytes, 0, (Int. Fs.Length); RequestStream.Flush (); RequestStream.Close (); } Byte [] imageToByteArray (image image) {MemoryStream ms = New MemoryStream (); ImageInSave (MS, System.Drawing.Imaging.ImageFormat.Jpeg); Return to MS. ToArray (); }  

How did someone do this for video files?

You should stream the entire file in one array instead of one block at one time. Otherwise, you will potentially use large amounts of memory because video files can be quite large.

For example:

  HttpWebRequest request; request. Method = "put"; (Stream requeststream =) using request.GetRequestStream ()) (stream video = file.openride ("path")) {byte [] buffer = new byte [4096]; While (true) {int bytesRead = video.Read (buffer, 0, buffer lang); If breaks (bytes read == 0); Requeststream.Write (buffer, 0, bytes read); }}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -