将图像发布到 asp.net mvc 控制器操作
我正在尝试创建一个 asp.net mvc 控制器方法,该方法将返回由 POSTed 字节数组生成的图像。该帖子来自 Flash,并具有请求标头:“Content-type”、“application/octet-stream”(尽管可以根据需要更改)。
我试图实现的代码来自 http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed- saving-images-from-flash/ 其中给出了一个使用 flash 和 php 的示例,如下所示:
AS3
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("jpg_encoder_download.php?name=sketch.jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");
php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
// get bytearray
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
// add headers for download dialog-box
header('Content-Type: image/jpeg');
header("Content-Disposition: attachment; filename=".$_GET['name']);
echo $jpg;
}
谁能建议一个等效的 ASP.NET MVC 控制器方法可能是什么样子?
ASP.Net MVC
public ActionResult DownloadImage(??? ???)
{
var myStream:FileStream = ???;
return new FileStreamResult(new FileStream(myStream, FileMode.Open), "image/jpeg");
}
I'm trying to create an asp.net mvc controller method that will return an image generated by a POSTed bytearray. The post is coming from Flash and has the request header: "Content-type", "application/octet-stream" (although this can be changed if needed).
The code I'm trying to implement is from http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash/ which gives an example with flash and php as follows:
AS3
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("jpg_encoder_download.php?name=sketch.jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");
php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
// get bytearray
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
// add headers for download dialog-box
header('Content-Type: image/jpeg');
header("Content-Disposition: attachment; filename=".$_GET['name']);
echo $jpg;
}
Can anyone suggest what an equivilent asp.net MVC controller method might look like?
ASP.Net MVC
public ActionResult DownloadImage(??? ???)
{
var myStream:FileStream = ???;
return new FileStreamResult(new FileStream(myStream, FileMode.Open), "image/jpeg");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以查看以下博客文章,其中说明了ASP.NET MVC 中如何处理文件上传
You may checkout the following blog post which illustrates how file uploads are handled in ASP.NET MVC
我用过类似的东西。看看这个。
问候
帕明德
I have used something similar. Check this out.
Regards
Parminder