将 sendAsBinary 与 ASP.Net MVC 结合使用
我正在尝试使用以下内容来允许用户将照片拖到页面上并上传这些照片。
现在我一直在尝试让模型绑定工作,但到目前为止还没有内置任何东西。有谁知道我如何才能让它工作???
作为备份,我知道我使用 InputStream 将发送的数据作为字符串拉出,然后 sdserialize 到我的对象中...
var stream = this.Request.InputStream;
var result = "";
using (var reader = new StreamReader(stream))
{
result = reader.ReadToEnd();
}
var serializer = new JavaScriptSerializer();
var typedObjectResult = serializer.Deserialize<UploadInput>(result);
但是我正在将消息的图像部分转换为字节数组,然后将其保存到一个文件。图像的字符串内容如下所示。
data:image/jpeg;base64,/9j/4RjhRXhpZg........3Xuve9de6//9k=
我如何将其另存为图像?我应该能够将字节数组写入文件吗?
但我主要关心的是模型绑定是否正确。
干杯
I'm trying to use the following to allow a user to drag photos onto a page and have those photos uploaded.
Now I've been trying to get the model binding working of this but thus far haven't had much luck with anything built in. Does anyone know how I could get this to work???
As a backup, I know I use the InputStream to pull the sent data out as a string and then sdserialize into my object...
var stream = this.Request.InputStream;
var result = "";
using (var reader = new StreamReader(stream))
{
result = reader.ReadToEnd();
}
var serializer = new JavaScriptSerializer();
var typedObjectResult = serializer.Deserialize<UploadInput>(result);
But I'm having converting the image part of the message into a byte array and then saving that off to a file. The string content of the image looks like this.
data:image/jpeg;base64,/9j/4RjhRXhpZg........3Xuve9de6//9k=
How do I save this as an image? Should I just be able to write the byte array to a file?
But my main concern is getting the model binding right.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,让我们将其付诸行动。一如既往,首先定义视图模型:
然后是控制器:
最后是视图:
现在启动您的 HTML 5 兼容浏览器并享受乐趣。
OK, let's put this into action. As always start by defining a view model:
then a controller:
and finally a view:
Now fire up your HTML 5 compliant browser and have fun.