Respond problem for upload image
Question
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 problemAnswers (3)
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
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2009
'Select' trait no updated in edit mode
Hi there, There is a problem with me, I don't know if it from my code or from grapejs itself, For LINK tool, it takes its links from my DB...
Issue #932
Setting background image results in duplicate style rules
Hi @artf, I have one strange little problem. I have a custom trait which has an implementation for setting images and background images. Wh...
Issue #933
Setting backgroud image results in duplicate style rules
Hi @artf, I have one strange little problem. I have a custom trait which has an implementation for setting images and background images. Wh...
Issue #1026
GrapeJS can't render HTML code
Hi, I intergrated GrapesJS to my application (asp.net MVC) and it works but sometimes GrapesJS can't render HTML. First, I clone html from...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.