function d_images = download_images(JSONString)

pkg load image
JSONSentinel = JSONString
B4URL = JSONSentinel.Band4URI
%create URLs
UID = JSONSentinel.UID
B8URL = strrep(B4URL,"B04.jp2","B08.jp2")
B11URL = strrep(B4URL,"B04.jp2","B11.jp2")
B8AURL = strrep(B4URL,"B04.jp2","B8A.jp2")
TCIURL = strrep(B4URL,"B04.jp2","TCI.jp2")
B5URL = strrep(B4URL,"B05.jp2","TCI.jp2")
B4FileName = 'TileB4.jp2';
B8FileName = 'TileB8.jp2';
TCIFileName = 'TileTCI.jp2';
B8AFileName = 'TileB8A.jp2';
B11FileName = 'TileB11.jp2';
B5FileName = 'TileB5.jp2';

%download images
wait_t = randi(10)
pause(wait_t)
try
	urlwrite(B4URL,B4FileName);

wait_t = randi(10)
pause(wait_t)

urlwrite(B8URL,B8FileName);

wait_t = randi(10)
pause(wait_t)

urlwrite(TCIURL,TCIFileName);

wait_t = randi(10)
pause(wait_t)

urlwrite(B11URL,B11FileName);

wait_t = randi(10)
pause(wait_t)

urlwrite(B8AURL,B8AFileName);
wait_t = randi(10)
pause(wait_t)

urlwrite(B5URL,B5FileName);
d_images = strcat(UID,"successful")
catch
        d_images = 'failed due to HTTP Error'
        d_images = strcat(UID,"failed4")
        return
end
end
