I am working on mischi plugin to resize and upload image to server:
Everything goes okay except uploading server part.
I am not sure how should it looks like server code to get "image".
if image is regular image to upload this server code works fine:
[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 { { Result= 1 } };
}
and console out put of that image looks like:
However for resized image, its console log out put looks like:
So is this called canvase image?
This is angularjs code for client side:
$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;
});
};
How should look like its server code?
I tried this but no luck:
[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});
}
which is wrong image parameter is null
Aucun commentaire:
Enregistrer un commentaire