将图像发布到 asp.net mvc 控制器操作

发布于 2024-10-12 16:52:51 字数 1433 浏览 2 评论 0原文

我正在尝试创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心头的小情儿 2024-10-19 16:52:51

您可以查看以下博客文章,其中说明了ASP.NET MVC 中如何处理文件上传

You may checkout the following blog post which illustrates how file uploads are handled in ASP.NET MVC

简美 2024-10-19 16:52:51

我用过类似的东西。看看这个。

var image = new Bitmap(Request.InputStream);
string fileName = Guid.NewGuid() + ".jpg";
image.Save(Server.MapPath("somefolder"+fileName));

问候
帕明德

I have used something similar. Check this out.

var image = new Bitmap(Request.InputStream);
string fileName = Guid.NewGuid() + ".jpg";
image.Save(Server.MapPath("somefolder"+fileName));

Regards
Parminder

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文