作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究mischi plugin调整图像大小并将图像上传到服务器:
除了上传服务器部分之外一切正常。
我不确定获取“图像”的服务器代码应该是什么样子。
如果图像是常规图像,则上传此服务器代码工作正常:
[HttpPost]
public JsonResult SaveFiles()
{
if (Request.Files != null)
{
var file = Request.Files[0];
actualFileName = file.FileName;
int size = file.ContentLength;
file.SaveAs(Path.Combine(Server.MapPath("~/UploadedFiles"), fileName));
}
return Json { new { Result= 1 } };
}
该图像的控制台输出如下所示: .
但是,对于调整大小的图像,其控制台注销输出如下所示:
这就是所谓的 Canvas 图像吗?
这是客户端的 angularjs 代码:
$scope.single = function(image) {
var formData = new FormData();
formData.append('image', image, image.name);
$http.post('/Photo/UploadPhoto', formData, {
headers: { 'Content-Type': undefined},
transformRequest: angular.identity
}).success(function(result) {
$scope.uploadedImgSrc = result.src;
$scope.sizeInBytes = result.size;
});
};
它的服务器代码应该是什么样子?
我尝试过,但没有成功:
[HttpPost]
public JsonResult UploadPhoto(string image)
{
var count = Request.Files.Count; //gives me 0
string fileName = "somefilename.png";
string fileNameWitPath = Path.Combine(Server.MapPath("~/"), fileName);
using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(image);
bw.Write(data);
bw.Close();
}
fs.Close();
}
return Json(new { result = 1});
}
这是错误的image
参数为空
最佳答案
公共(public) JsonResult 索引(HttpPostedFileBase 图像){...}
关于javascript - 用于上传调整大小的图像的服务器代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29450944/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!