2
I already have a webservice for which I pass an image (Base64) and it saved on my server. So far it is working perfectly.
On my screen is this code :
function salvar() {
var dados = {};
//Utilizar o toDataURL para converter em Base64
var base64 = document.getElementById("myCanvas").toDataURL("image/png");
dados.base64 = base64.substr(base64.indexOf(',') + 1, base64.length);
var WPath = "face1";
$.ajax({
type: 'POST',
//Chamar o webmethod SalvarImagem em webservice.asmx
url: "SalvarImagem.asmx/SalvarImagemX",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify(dados, WPath),
success: function (data) {
alert(data.d);
}
, error: function (xmlHttpRequest, status, err) {
alert("Ocorreu o seguinte erro:" + xmlHttpRequest.responseText)
}
});
}
And my webservice is like this :
public class SalvarImagem : System.Web.Services.WebService
{
[WebMethod]
public string SalvarImagemX(string base64, string WPath)
{
//MemoryStream com o base64 recebido por parâmetro
using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64)))
{
//Criar um novo Bitmap baseado na MemoryStream
using (Bitmap bmp = new Bitmap(ms))
{
//Local onde vamos salvar a imagem (raiz do site + /canvas.png)
//string path = Server.MapPath("/" + WPath + "/canvas.png");
string path = Server.MapPath("/face2/canvas.png");
//Salvar a imagem no formato PNG
bmp.Save(path, ImageFormat.Png);
}
}
return "Imagem foi salva com sucesso";
}
}
}
My problem is that : As I said it works while I only pass a parameter that is the DATA string. But I also need to pass another string that contains the folder where the image should be saved...
When I put second parameter (Wpath) I started getting the error message below... Can anyone tell me what’s wrong ....??
The following error occurred:
{"Message":"Invalid web service call, Missing value for Parameter: u0027WPath u0027." ,"Stacktrace":" at System.Web.Script.Services.Webservicemethoddata.Callmethod(Object target, Idictionary
2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary
2 Parameters) r n at System.Web.Script.Services.Resthandler.Invokemethod(Httpcontext context, Webservicemethoddata methodData, Idictionary`2 rawParams) r n at System.Web.Script.Services.Resthandler.Executewebservicecall(Httpcontext context, Webservicemethoddata methodData)","Exceptiontype":"System.Invalidoperationexception"}
Okay. I found out... one ',' was missing at the end...
– Eduardo
Hello, don’t post additional questions as an answer, instead post a comment in a response that generated the question. Did my answer help? Then mark it as accepted. You can also vote on other questions and answers on the site
– Artur Trapp
Ola did what you suggested and went on to give this mistake... The following error occurred:{"Message":"The input is not a Valid Base-64 string as it contains a non-base 64 Character, more than two padding characters, or an illegal Character Among the padding characters.
– Eduardo