1
我正在使用c#.net compact framework 3.5,我想將視頻文件轉換爲字節數組,以便我可以將其上載到服務器上。如何將視頻轉換爲C#中的字節數組(c sharp)?
以類似的方式我這樣做這是越來越成功的結果圖片上傳....
HttpWebRequest request;
request.ContentType = "image/jpeg";
request.ContentLength = byteArray.Length;
request.Method = "PUT";
imageToByteArray(img).CopyTo(byteArray, 0);
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(byteArray, 0, (int)Fs.Length);
requestStream.Flush();
requestStream.Close();
}
public byte[] imageToByteArray(Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
有人有想法如何爲視頻文件做到這一點?
你加載整個事情兩次在內存中。最好打開一個FileStream並將其複製到請求流中。請參閱http://stackoverflow.com/questions/230128/best-way-to-copy-between-two-stream-instances-c和http://stackoverflow.com/questions/1493594/writing-a-stream-to -asp-response-in-asp-net和http://stackoverflow.com/questions/674651/uploading-files-past-asp-net-request-length-limit – Will 2009-10-20 12:11:36