I am generating a canvas within my application, then I would like to upload what is believed in that canvas as a% png
image to my server. The problem I'm having is that it goes up, obviously with weight but the image can not be seen.
The canvas is in base 64
var img_b64 = fotoFirmaService.getImagenFirma(); //base64 de la imagen
var png = img_b64.split(',')[1];
var the_file = new Blob([window.atob(png)], { type: 'image/png', encoding: 'utf-8' });
var imagen_firma = new File([the_file], 'imagen_firma.png', { type: 'image/png' });
When I print the value of imagen_firma
I get:
File {
lastModified : 1489088454413
lastModifiedDate : Thu Mar 09 2017 16:40:54 GMT-0300 (CLT)
name : "imagen_firma.png"
size : 16926
type : "image/png"
webkitRelativePath : ""
}
However, the image on my server is empty. I do the same procedure with input type file, but upload correctly. I print the structure of those files and they are identical to this File but in this case it does not work.
EDIT
It is with this code that I upload the file to my server:
var payload = new FormData();
payload.append('file', imagen_firma);
$http({
method: 'POST',
url: 'dsaasas/UploadImage/' + imagen_firma.name,
data: payload,
headers: { 'Content-Type': undefined },
transformRequest: angular.identity
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log("bien");
console.log(response);
}, function errorCallback(response) {
console.log(response);
// called asynchronously if an error occurs
// or server returns response with an error status.
});
And this is my C # code, it's with WCF
public string UploadImage(string fileName)
{
try
{
HttpPostedFile file = HttpContext.Current.Request.Files[0];
if (file == null)
return null;
string targetFilePath = WebConfigurationManager.AppSettings["FilePath"] + fileName;
file.SaveAs(targetFilePath);
return "succ " + file.FileName.ToString();
//return fileName;
}
catch (Exception ex)
{
return ex.Message + " - " + ex.InnerException;
}
}