Respond problem for upload image
I know is an old problem but I have an issue for the respond where I tried to return a response by using asp.net to return a response below is my code(services code to save into directory and return a response): (code in ashx asp.net) ` context.Response.ContentType = "text/plain"; context.Response.Expires = -1; try { HttpPostedFile postedFile = context.Request.Files[0] as HttpPostedFile; string tempPath = "/uploadImg"; string savePath = context.Server.MapPath(tempPath); string filename = postedFile.FileName; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string path = savePath + @"" + filename; postedFile.SaveAs(path);
Stream s = postedFile.InputStream;
Image img = System.Drawing.Image.FromStream(s);
int imgHeight = (int)img.PhysicalDimension.Height;
int imgWidth = (int)img.PhysicalDimension.Width;
TempModel tempModel = new TempModel();
tempModel.type = "image";
tempModel.src = "http://localhost:2002" + tempPath + "/" + filename;
tempModel.height = imgHeight.ToString();
tempModel.width = imgWidth.ToString();
TempData tempData = new TempData();
tempData.data = new List<TempModel>();
tempData.data.Add(tempModel);
string jsonString = JsonConvert.SerializeObject(tempData);
string jsonRespond = jsonString.Insert(9,"\"" + "http://localhost:2002" + tempPath + "/\",");
context.Response.Write(jsonRespond);
context.Response.StatusCode = 200;
}catch(Exception ex)
{
context.Response.Write("Error: " + ex.Message);
}`
the code can save image to the directory but there is an error when parsing the response at grapesjs what I facing is when i dropped my image the image couldn't automatic show in the panel. I refered to the #138 but still having response problem
there is an error when parsing the response at grapesjs
Which error???
Probably just try to change context.Response.ContentType = "text/plain"; with context.Response.ContentType = "application/json";
hi @artf the error is
I tried changed the context.Response.ContentType = "application/json"; but still get the above error
and my response from service is as below
the response get by using Fiddler 4.
and I would like to check whether the require response as above because it is weird that response from #138 where the one of the response does not have any key.
Unexpected token E in JSON at position 0 means your response it's not a valid JSON string (which should start, for instance, with { or [ not E, probably there is an Error...). Check the response in your dev tools and you will see it
I know where is the issue. It is my directory used by other process therefore it cause Error that catch at the end. I think i need to change the code in the service to solve the problem. Thanks @artf for assisting me in this time.
@richieteh94 how did you solve this problem?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.