How to download PNG/PDF content with url in Chromium browser?

Based on my previous question (How to use 'POST url' to share visualisation in my website?), I think it is better to open a new topic because the question changes to another area.

I sent POST url and get JSON file back. I can find generated reports in 'Management'->'Reporting'. I can get the following url for visualisation which is opened in Chromium browser (http://localhost:5601/api/reporting/jobs/download/jvi1f14j06559d006290mkfc). I wrote the following code to download this file in my local public folder:
File.open('./public/testfile.png', "wb") do |file|
file.write open('http://localhost:5601/api/reporting/jobs/download/jvhq4luc06559d0062d29e9d')
end

But I cannot open the download file at all. I think it is because the url doesn't have '.pdf' suffix and it is opened in Chromium browser, not Chrome.

The following is the information of reporting in Kibana. The content of reporting file is PNG.I would like to know if there is a way to download/save the content 'PNG/PDF' of this url in my local folder?

@landy

To download the report, you don't need to open the file with a browser at all. You can just issue a GET-request for the report (e.g. in pdf or png) and save it to disk. Give the name of the file you are saving it to the correct extention (e.g. .pdf or .png), just to make sure it opens up fine locally.

It will depend a little on the programming language you're using, but with cUrl it would look something like this from the command line.

curl -o download.png http://localhost:5601/api/reporting/jobs/download/jvn6b6y606fs0c86b53gpjs7

I'm not really all that familiar with Ruby, so I'm not sure why you can't just save the contents. But maybe this SO question is helpful, especially the answer that uses the append operator: https://stackoverflow.com/questions/2515931/how-can-i-download-a-file-from-a-url-and-save-it-in-rails

Thanks a lot Thomas! I download PNG file successfully by using 'wget' and 'open-uri'(the link you put). Both of them work. The problem why I can't download the file is: After sending POST URL, Kibana server needs some time to generate the report. It will show me 'pending', 'processing'. If I try to download report immediately, the file is still blank. So I need to put 'sleep(7.0)' before the download code.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.