CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Downloading an image file

by XenoG » 06 Dec 2017 21:28

I'm trying to provide users with the ability to download an image file (jpg) of an TIWCGJQImage that is shown on screen. If I try to do it all in one button click, I find that the download does not work (Chrome seems to buffer it until I do another download later). I am using the following two methods

IWCGJQImage1->SaveImage(downloadFileName);
IWCGJQFileDownload1->DownloadFileName(downloadFileName);

I assume that I need to wait until the image is saved to the server before the download will succeed. If I split these two methods into separate buttons, then I can save the image file to the server and then download it into the browser.

Is there a way to do this all in one button click?

Thanks,

Richard
XenoG
 
Posts: 36
Joined: 15 Nov 2016 15:04

by Jorge Sousa » 07 Dec 2017 12:44

Hi there

In fact, when you code

IWCGJQImage1->SaveImage(downloadFileName);

the image is only saved instantly if you have have an image loaded in IWCGJQImage1.Picture.Graphic

If not, ie, if you have an url, the statement only will instruct browser to send image data to be saved AFTER the async event is processed, so

when the browser counterpart of

IWCGJQFileDownload1->DownloadFileName(downloadFileName);

is called, the filename is still not there.

You will have to use the data event IWCGJQImage1->OnAfterSave event, and an IWTimer

Since OnAfterSave is not an IW Async or Submit event, you cannot call or refer an IW related method or component

Now, another problem is that if you have another domain in your IWCGJQImage.Picture.Url, and will face cross-domain issues, and you cannot use SaveImage, chrome, fi will raise the following error:

Code: Select all
redirect from 'http://www.cgdevtools.com/wp-content/uploads/2015/08/logo_cgdevtools1.png' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8888' is therefore not allowed access.

Please see the enclosed demo, and set the output path CGDevTools demo-bin path
You do not have the required permissions to view the files attached to this post.
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by XenoG » 07 Dec 2017 17:27

Many thanks Jorge. The method using the timer works perfectly.

Could I ask for one more piece of advice. The image that I am saving and downloading should ideally be hidden. I am actually trying to download the image of a IWCGJQPlot, so I am using

IWCGJQPlot->ChartToImage(IWCGJQImage1);

to take the image from the TIWCGJQPlot to the TIWCGJQImage and then using your technique to download the image file to the client's browser.

Is there a way of getting the image from the TIWCGJQPlot into a hidden (visible = false?) TIWCGJQImage and then use the timer method to get the image download?

Thanks again,

Richard
XenoG
 
Posts: 36
Joined: 15 Nov 2016 15:04

by Jorge Sousa » 07 Dec 2017 17:51

Hi Richard

As far as I know, you can set IWJQImage1.Visible = False, as long as is parent has RenderInvisibleControls = True

Please check
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by XenoG » 07 Dec 2017 19:57

Jorge,

You are on fire today :) It works perfectly. Many thanks.

I noticed that someone else asked a question on the forum about how to save and download images from TIWCGJQPlot objects. I'll document a reply so that Google can find the answer for anyone else that wants to do this.

Thanks again,

Richard
XenoG
 
Posts: 36
Joined: 15 Nov 2016 15:04


Return to JQImage

cron

Who is online

Users browsing this forum: No registered users and 3 guests

Contact Us.