开发者

How do I retrieve the binary contents of a longblob column and save as a file?

开发者 https://www.devze.com 2023-04-12 04:31 出处:网络
A *.rar file was saved in a column longblob, but it was saved as bin开发者_StackOverflowary. How can I build this file in vb.net?

A *.rar file was saved in a column longblob, but it was saved as bin开发者_StackOverflowary.

How can I build this file in vb.net?

For example I download its binary code with below query.

Select file from table where id=1

Then do I save it on a variable string? What is the best way for rebuild this .rar?


Once you have selected the field, cast the return object into byte[], and do what you need with it. If you need to send it to a user, through the browser, simple set mime type and filename, and write the byte[] to the outputstream. This is how I would do it, but with C# code:

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号