How to have the MATLAB Web Browser automatically save a downloaded file to a specified directory without prompting

14 views (last 30 days)
Basically I have a script that downloads a series of files from an intranet repository. For each file that the browser attempts to download, a prompt appears which asks which directory to save the file to. Is it possible to have MATLAB skip that prompt and download the file automatically? Additionally, is it possible to specify what path the downloaded file should be saved to?
I used to be able to achieve this by having MATLAB use Chrome to download the file, but Chrome is no longer supported by the respository I'm downloading from. I can have it use Internet Explorer and specify a download folder in the IE options, but I still have to manually click "open" or "save" for each downloaded file. Either way, if I use an external browser, I have to log into the repository from both the MATLAB browser and the external browser, and I'm not able to have MATLAB detect whether a login is necessary for the external browser, which is helpful for having my script run smoothly.

Answers (2)

Mohammad Sami
Mohammad Sami on 23 Aug 2020
If you have direct links to the file, you can use websave function to save them to the specified location.
if true
url = 'http://heritage.stsci.edu/2007/14/images/p0714aa.jpg';
filename = 'jupiter_aurora.jpg'; % path to save the downloaded file
outfilename = websave(filename,url);
end
More details are available in documentation. https://www.mathworks.com/help/matlab/ref/websave.html

Kiran Felix Robert
Kiran Felix Robert on 24 Aug 2020
Hi Philip,
To download and save the files the websave function can be used. You can specify the path using the filename argument or you can save to the default location and move these later.
Assuming you have the specific URL to all the files (assuming all are csv files), and you want to set the output file name using an iterator, the following example can be used,
(URL is the array which contains the direct links to all the files. Refer num2str.)
for i = 1:N % N is the number of files to retrieve
path_to_save = "C:/WebFiles/";
out_name_path = path_to_save+num2str(i)+".csv"; % This way can be used if iteration is needed
outfilename = websave(out_name_path,URL(i));
end
Kiran Felix Robert

Categories

Find more on Downloads in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!