gpt4 book ai didi

javascript - 用于上传调整大小的图像的服务器代码

转载 作者:行者123 更新时间:2023-11-28 07:27:46 25 4
gpt4 key购买 nike

我正在研究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 } };
}

该图像的控制台输出如下所示: enter image description here .

但是,对于调整大小的图像,其控制台注销输出如下所示: enter image description here

这就是所谓的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com