我正在尝试创建一个asp.net mvc控制器方法,该方法将返回由POSTed bytearray生成的图像。该帖子来自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");
}
答案 0 :(得分:4)
您可以查看以下blog post,其中说明了如何在ASP.NET MVC中处理文件上传
答案 1 :(得分:1)
我使用了类似的东西。看看这个。
var image = new Bitmap(Request.InputStream);
string fileName = Guid.NewGuid() + ".jpg";
image.Save(Server.MapPath("somefolder"+fileName));
此致 Parminder