Stream轉為byte[],可能Stream的Read方法的count參數會因為byte數組長度太長超過int最大值報錯,目前我還沒找到解決方案。。。
1 public static byte[] StreamToBytes(this Stream stream) 2 { 3 byte[] bytes = new byte[stream.Length]; 4 try 5 { 6 stream.Read(bytes, 0, bytes.Length); 7 // 設置當前流的位置為流的開始 8 stream.Seek(0, SeekOrigin.Begin); 9 return bytes; 10 } 11 catch (Exception ex) 12 { 13 LogUtil.Log.Error("將Stream轉為Byte[]時錯誤", ex); 14 } 15 return bytes; 16 }