c# - Download All Blobs from single Azure Container -
i'm trying download blobs single azure container using code. when download each blob want new file names consecutive numbers 2.jpg upwards through 3.jpg, 4.jpg 5.jpg etc. not name of blobs in azure container, dont know name of each blob when code runs.
i seem falling @ last hurdle, cant figure out put foreach
block files \home\pi\pictures\
directory on local hard drive.
urls.downloadtostream(filestream);
throwing error
list string not contain definition downloadtostream
and
filestream type not valid in given context.
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.collections; using microsoft.windowsazure; using microsoft.windowsazure.storage; using microsoft.windowsazure.storage.auth; using microsoft.windowsazure.storage.blob; using system.configuration; using system.io; using system.data; using system.data.sqlclient; using system.threading; namespace cpgetadverts { class program { static void main(string[] args) { // retrieve storage account connection string. cloudstorageaccount storageaccount = cloudstorageaccount.parse(configurationmanager.connectionstrings["azureimagesconnection"].connectionstring); // create blob client. cloudblobclient blobclient = storageaccount.createcloudblobclient(); // retrieve reference container. var container = blobclient.getcontainerreference("xxxxxx/").listblobs(); // retrieve filenames container list var urls = new list<string>(); int filename = 2; foreach (var blob in container) { using (var filestream = system.io.file.openwrite(@"\home\pi\pictures\"+ filename + ".jpg")) ; urls.downloadtostream(filestream); filename++; } } } }
any appreciated.
a couple issues line:
urls.downloadtostream(filestream);
- urls list of strings won't contain
downloadtostream
method filestream
shouldfilestream
try changing loop like:
foreach (var blob in container) { using (var filestream = system.io.file.openwrite(@"\home\pi\pictures\"+ filename + ".jpg")) { var blobreference = blobclient.getblobreferencefromserver(blob.uri); blobreference.downloadtostream(filestream); filename++; } }
Comments
Post a Comment