我们正在从网络服务获取输入 byte[]
(我们内部处理)并且我们需要上传到另一个仅接受文件流的网络服务。
如何转换byte[]
在 C# 中不写入磁盘到文件流?
编辑:这不是重复的。我不是问如何转换byte[]
到内存流或文件流。我问如何转换byte[]
到文件流而不写入磁盘。请注意,我需要将数据作为文件流发送到我无权访问的第三方网络服务。此 Web 服务仅接受文件流。
到目前为止我有以下代码:
string fileWritePath = "c:\\temp\\test.docx";
//here fileContent is a byte[]
File.WriteAllBytes(fileWritePath, fileContent);
FileStream fileStream = new FileStream(fileWritePath, FileMode.Open, FileAccess.Read);
我不想将文件写入本地磁盘并创建文件流。
最佳答案
使用MemoryStream
:
using(var stream = new MemoryStream(byteArray)){
SendStreamToService(stream);
}
关于c# - 将 byte[] 转换为文件流而不写入磁盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41244244/