フィルターのクリア

Download files from an URL

3 ビュー (過去 30 日間)
Haron Shaker
Haron Shaker 2021 年 2 月 27 日
回答済み: Sai Veeramachaneni 2021 年 3 月 2 日
Dear all,
I wrote an function, which should download folder given in 'founded_medicine_folder.xls' as an url (see attachment). Unfortunately, I get an error, where it says:
'Error using fopen
First input must be a file name or a file identifier.
Error in download_edf>downloadFolderContentToCellArray
(line 31)
fileID = fopen(fileName, 'w');
Error in download_edf (line 2)
downloadFolderContentToCellArray(folderCellArrayData)'
1)What should I change that it considers the URL as an filename?
2) Can you observe if it would work?
folderCellArrayData = readcell('founded_medicine_folder.xls')
downloadFolderContentToCellArray(folderCellArrayData)
function downloadFolderContentToCellArray(folderCellArrayData)
import matlab.net.http.*
%add password, didn't want it to stay in code
creds = Credentials('Username', '', 'Password', '');
options = HTTPOptions('Credentials', creds, 'ConnectTimeout', 60);
len = length(folderCellArrayData);
%TODO make it first line or someting and not a sudden magic number
%currently first line descriptions of content
%following two empty lines
for x = 1:len
%filetype = folderCellArrayData{x,3};
url = folderCellArrayData{x,1};
%if ~(strcmp(filetype, 'folder'))
resp = RequestMessage().send(url , options);
%find file name
i = strsplit(url, '/');
y = length(i);
fileName = i(y);
%save file in temp folder
fileID = fopen(fileName, 'w');
fprintf(fileID, '%s', resp.Body.Data);
fclose(fileID);
%end
end
end

採用された回答

Sai Veeramachaneni
Sai Veeramachaneni 2021 年 3 月 2 日
Hi,
i = strsplit(url, '/');
y = length(i);
fileName = i(y);
It seems that above lines of code makes the fileName variable to be of type cell array.
quick resolution would be to change type of fileName variable.
fileName = i{y}
Hope it helps.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by