PDA

View Full Version : [CLOSED] while saving image on server it throwing No Response error



PriceRightHTML5team
Jan 27, 2014, 12:43 PM
Hi,

while saving image on server image getting No Response error after successfully uploading of Image on server.

following is code

HTML markup



Html.X().Button().ID("btnSaveImage").Text("Save Image")
.Scale(ButtonScale.Small).Icon(Icon.PageExcel).Typ e(ButtonType.Button)
.DirectEvents(de =>
{
de.Click.Url = Url.Action("GetReportGraphToExport", "InternalPricing");
de.Click.EventMask.ShowMask = true;
de.Click.Timeout = 50000;
de.Click.Before = "App.cntrGenerateReportGraph.removeAll();";
de.Click.FormID = "frmReportFilter";
de.Click.Failure = "Ext.Msg.alert('There is an error to load report.');";
de.Click.Success = "saveChart('ReportChart',true);";
}),

JavaScript Method


function saveChart(chartName,saveOnServer){
var barChart = Ext.getCmp(chartName);
var svg1 = barChart.save({ type: 'image/svg+xml' });
var svg1Width = barChart.width;


Ext.net.DirectMethod.request({
url: '@Url.Action("SaveSvg", "InternalPricing")',
cleanRequest: true,
isUpload: true,
params: {
svg1: svg1,
svg1Width: svg1Width,
saveOnServer:saveOnServer

}

});
}

Server side code


public void SaveSvg(string svg1, int svg1Width, bool saveOnServer)
{
try
{

XmlDocument xd = new XmlDocument();
xd.XmlResolver = null;
xd.LoadXml(Server.HtmlDecode(svg1));
SvgDocument svgGraph = null;
svgGraph = Svg.SvgDocument.Open(xd);

Bitmap firstImage = svgGraph.Draw();

using (Bitmap result = new Bitmap(firstImage.Width, firstImage.Height))
{
using (var canvas = Graphics.FromImage(result))
{
canvas.Clear(System.Drawing.Color.White);
canvas.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic;
canvas.DrawImage(firstImage, new Rectangle(0, 0, firstImage.Width, firstImage.Height), new Rectangle(0, 0, firstImage.Width, firstImage.Height), GraphicsUnit.Pixel);

canvas.Save();
}
string path = System.Web.HttpContext.Current.Server.MapPath(
string.Concat( PriceRight.Settings.PropertyReader.GetProperty("SavedChart"),
"chart.png"
) );
if (saveOnServer == true)
{
result.Save(path, System.Drawing.Imaging.ImageFormat.Png);
}
else
{
HttpContext.Response.Clear();
Response.Buffer = true;
HttpContext.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}{1}", "chart", ".png"));
Response.Charset = "";
HttpContext.Response.ContentType = "image/Png";
result.Save(HttpContext.Response.OutputStream, ImageFormat.Png);
Response.Flush();
Response.End();
}
}
}

geoffrey.mcgill
Jan 27, 2014, 2:53 PM
Please review the following guidelines for posting in the forums:

http://forums.ext.net/showthread.php?3440-Forum-Guidelines-For-Posting-New-Topics

http://forums.ext.net/showthread.php?10205-More-Information-Required

PriceRightHTML5team
Jan 28, 2014, 4:55 AM
Hi,

On button click i m trying to save image on server but it throwing No Response error after successfully uploading of Image on server.

I am using Ext.net version 2.2.0.26551

View


Html.X().Button().ID("btnSaveImage").Text("Save Image")
.Scale(ButtonScale.Small).Icon(Icon.PageExcel).Typ e(ButtonType.Button)
.DirectEvents(de =>
{
de.Click.Url = Url.Action("GetReportGraphToExport", "InternalPricing");
de.Click.EventMask.ShowMask = true;
de.Click.Timeout = 50000;
de.Click.Before = "App.cntrGenerateReportGraph.removeAll();";
de.Click.FormID = "frmReportFilter";
de.Click.Failure = "Ext.Msg.alert('There is an error to load report.');";
de.Click.Success = "saveChart('ReportChart',true);";
})

JavaScript Method


function saveChart(chartName,saveOnServer){
var barChart = Ext.getCmp(chartName);
var svg1 = barChart.save({ type: 'image/svg+xml' });
var svg1Width = barChart.width;


Ext.net.DirectMethod.request({
url: '@Url.Action("SaveSvg", "InternalPricing")',
cleanRequest: true,
isUpload: true,
params: {
svg1: svg1,
svg1Width: svg1Width,
saveOnServer:saveOnServer

}

});
}

Controller Action method

public void SaveSvg(string svg1, int svg1Width, bool saveOnServer)
{
try
{

XmlDocument xd = new XmlDocument();
xd.XmlResolver = null;
xd.LoadXml(Server.HtmlDecode(svg1));
SvgDocument svgGraph = null;
svgGraph = Svg.SvgDocument.Open(xd);

Bitmap firstImage = svgGraph.Draw();

using (Bitmap result = new Bitmap(firstImage.Width, firstImage.Height))
{
using (var canvas = Graphics.FromImage(result))
{
canvas.Clear(System.Drawing.Color.White);
canvas.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic;
canvas.DrawImage(firstImage, new Rectangle(0, 0, firstImage.Width, firstImage.Height), new Rectangle(0, 0, firstImage.Width, firstImage.Height), GraphicsUnit.Pixel);

canvas.Save();
}
string path = System.Web.HttpContext.Current.Server.MapPath(
string.Concat( PriceRight.Settings.PropertyReader.GetProperty("SavedChart"),
"chart.png"
) );
if (saveOnServer == true)
{
result.Save(path, System.Drawing.Imaging.ImageFormat.Png);
}
else
{
HttpContext.Response.Clear();
Response.Buffer = true;
HttpContext.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}{1}", "chart", ".png"));
Response.Charset = "";
HttpContext.Response.ContentType = "image/Png";
result.Save(HttpContext.Response.OutputStream, ImageFormat.Png);
Response.Flush();
Response.End();
}
}
}

Daniil
Jan 28, 2014, 5:04 AM
Here is a quote from
More Information Required (http://forums.ext.net/showthread.php?10205)


Please do not repost the same code block in a new post... just EDIT your original post.

geoffrey.mcgill
Jan 28, 2014, 5:07 AM
It would be nice if you could post a full (but simplified) sample demonstrating the whole scenario.

I think the problem is that you're overwriting the Response stream. The DirectEvent needs a specific format for the Response, but you're clearing the Response.

Daniil
Jan 28, 2014, 5:37 AM
It might be OK to deal with a Response directly if you are going to return a file.

I am not sure, but please try to remove:

cleanRequest: true