【问题标题】:Converting Byte[] to stream file asp.net将 Byte[] 转换为流文件 asp.net
【发布时间】:2021-08-20 11:56:25
【问题描述】:

我需要将 Byte() 转换为流然后刷新 它在 asp.net 应用程序中

这是我的代码:

Dim fileBytes As Byte() = Nothing

....

apiProp.BodyRequest = New JavaScriptSerializer().Serialize(entFile)

apiProp.EndPoint = "example.com/DownloadFile"
apiProp = api.MessageInvoke(apiProp)
entResponse = JsonConvert.DeserializeObject(Of FileResponse)(apiProp.BodyResponse)
fileBytes = Convert.FromBase64String(entFile.fileContent)

我试过了:

Response.BinaryWrite(fileBytes)
Response.Flush()

我已经尝试过任何文件流、内存流等文件要求下载,但如果我下载文件,文件会损坏

我需要将文件转换为流,因为我必须在图像文件上添加水印。我使用 groupdocs.watermark 添加水印。

【问题讨论】:

  • 这能回答你的问题吗? ASP.NET file download from server
  • 否,因为我需要处理文件以添加水印,我使用 groupdocs.watermark 添加水印,库需要流/文件路径(字符串)参数,但我将文件保存在 base64我的服务器中的字符串。所以我无法获取文件路径(或者如果我的文件转换为 base64 字符串,我不明白如何获取文件路径)

标签: asp.net vb.net model-view-controller


【解决方案1】:
 using (Stream InputStream = fl.PostedFile.InputStream)
            {
                Object o = new object();
                lock (o)
                {
                    byte[] buffer = new byte[InputStream.Length];
                    InputStream.Read(buffer, 0, (int)InputStream.Length);
                    lock (o)
                    {
                        File.WriteAllBytes(rpath, buffer);
                        buffer = null;
                    }
                    InputStream.Close();
                }
            }

【讨论】:

  • 答案是 C#。问题是 VB.NET。
猜你喜欢
  • 1970-01-01
  • 2018-12-15
  • 1970-01-01
  • 1970-01-01
  • 2011-11-04
  • 2011-06-08
  • 1970-01-01
  • 1970-01-01
  • 2014-07-21
相关资源
最近更新 更多