Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Image is blank when trying to download the diagram image file (Read 1453 times)
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Image is blank when trying to download the diagram image file
Aug 31st, 2021 at 10:22pm
Print Post  
Hello,

We would like to allow users to download the diagram as a PNG image. However, currently the downloaded image file is empty (zero KB) and there is a message on the file saying "this file format is not supported".

Here is the controller code we are using:

Code (Java)
Select All
 public ActionResult DownloadDiagramImage(string diagramJson)
        {
                DiagramView view = DiagramView.FromJson(diagramJson);
                Image diagramImage = view.Diagram.CreateImage();
                MemoryStream memoryStream = new MemoryStream();
                diagramImage.Save(memoryStream, ImageFormat.Png);
                return File(memoryStream, "image/png", "diagram.png"));
        }
 



While there is a way to download it after first saving the file to the server, we would prefer to not have to read and write to a server folder in order to have a downloadable file. It seems that building it dynamically using the memory stream should work as we do this with dynamically created PDFs and Powerpoints using memory stream.

If you have any suggestions on how to build the diagram image dynamically and return the file from the controller method so that it can be downloaded client-side, that would be very much appreciated.

Thanks.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Image is blank when trying to download the diagram image file
Reply #1 - Sep 1st, 2021 at 1:20pm
Print Post  
Hi,

You'll need to reset stream's position to 0 before passing it to the File response:

Code
Select All
diagramImage.Save(memoryStream, ImageFormat.Png);
memoryStream.Position = 0;
return File(memoryStream, "image/png", "diagram.png"); 



or pass the stream bytes to File instead:

Code
Select All
return File(memoryStream.ToArray(), "image/png", "diagram.png");  



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Megan1717
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 39
Joined: Jun 20th, 2016
Re: Image is blank when trying to download the diagram image file
Reply #2 - Sep 2nd, 2021 at 11:47pm
Print Post  
That worked. Thanks very much!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint