如何发送一个二进制数据到客户端浏览器? [英] How do I send a binary blob to a client browser?

查看:213
本文介绍了如何发送一个二进制数据到客户端浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里请原谅哑新手问题; Web编程是不是我的专长......(脸红)

我有一个Web服务器上的aspx页面运行。我有一个包含任何类型的二进制文件的BLOB(字节数组),加上一个文件名。

我想推动这个文件通过浏览器到客户端下载和使用任何应用程序的默认此文件类型打开。我真的不希望将BLOB保存为服务器上的文件;这将离开,我只是不想去想一个可怕的家务一团糟。

我曾尝试使用Google这个问题,但我想我使用了错误的关键字。

这确实应该是显而易见如何做到这一点,但我有没有喜悦。

什么是成功?

谢谢!


解决方案

  Response.BinaryWrite(字节阵列);

您还应该设置内容类型

  Response.ContentType =应用程序/ PDF

但是,这会根据您的文件类型。

和文件名(以及一切融合在一起)是这样做的。

  Response.AddHeader(内容处置,
   的String.Format(附件;文件名= {0},文件名));
Response.ContentType =应用程序/ PDF
Response.BinaryWrite(字节阵列);

Pardon the dumb newbie question here; web programming isn't my forte... (blush)

I have an aspx page running on a web server. I have a blob (byte array) containing any kind of binary file, plus a file name.

I would like to push this file to be downloaded through the browser onto the client, and opened using whatever application is default for this file type. I really don't want to save the blob as a file on the server; that will leave a terrible housekeeping mess that I just don't want to think about.

I did try googling this question, but I guess I'm using the wrong keywords.

This really should be obvious how to do it, but I'm having no joy.

What is the trick?

Thanks!

解决方案

Response.BinaryWrite(byteArray);

You should also set the content type

Response.ContentType = "application/pdf";

But that will be based on your file type.

And the file name (and everything together) is done like this

Response.AddHeader("content-disposition", 
   String.Format("attachment;filename={0}", fileName));    
Response.ContentType = "application/pdf";
Response.BinaryWrite(byteArray);

这篇关于如何发送一个二进制数据到客户端浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆