【问题标题】:How do I retrieve the binary contents of a longblob column and save as a file?如何检索 longblob 列的二进制内容并保存为文件?
【发布时间】:2011-12-05 19:43:49
【问题描述】:

*.rar 文件保存在longblob 列中,但保存为二进制。

如何在 vb.net 中构建这个文件?

例如,我使用以下查询下载其二进制代码。

Select file from table where id=1

那么我是否将它保存在变量字符串中?重建这个.rar的最佳方法是什么?

【问题讨论】:

  • 你最初是如何获得数据库中的文件的?我想解决方案是完全相反。
  • 我想得到这个文件...我如何保存?好吧,它是从 php 开始保存的,但我想在 vb.net 桌面中重建它
  • 不要保存在字符串中保存在字节数组或流中!

标签: c# .net mysql file binary


【解决方案1】:

选择字段后,将返回对象转换为 byte[],然后使用它执行您需要的操作。 如果您需要将其发送给用户,通过浏览器,简单设置 mime 类型和文件名,并将 byte[] 写入输出流。 我就是这样做的,但是使用 C# 代码:

context.Response.ContentType = ReturnExtension(Extension);
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);

byte[] buffer = (byte[])DB.GetReposFile(id).Rows[0]["FileContent"];
context.Response.OutputStream.Write(buffer, 0, buffer.Length);

【讨论】:

  • 这是针对asp.net的,但没有提到在asp.net中这样做?
猜你喜欢
  • 2017-06-08
  • 2021-11-05
  • 2020-05-25
  • 2020-12-29
  • 1970-01-01
  • 2019-12-11
  • 1970-01-01
  • 1970-01-01
  • 2014-03-31
相关资源
最近更新 更多