Reputation: 463
I know there are similar questions like this one but none of them worked for me. I am trying to download a file from Azure storage. But I am getting an error and the error message is The specified blob does not exist. But the blob does exist and my connection string is also valid. I am sharing my code below. It would be helpful if someone can help me out.
Code:
public void downloadFile(ShowContentInfo showContentInfo){
ExecutorService executor = Executors.newSingleThreadExecutor();
Handler handler = new Handler(Looper.getMainLooper());
executor.execute(() ->{
CloudStorageAccount storageAccount = null;
try {
String dir = "/storage/emulated/0/Download/LmsContents/";
if (!dt.file.folderExists(dir)) {
dt.file.createFolder(dir);
}
storageAccount = CloudStorageAccount.parse(CONNECTION_STRING);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("containerName");
CloudBlockBlob blockBlob = container.getBlockBlobReference("rblobName");
File file = new File("/storage/emulated/0/Download/LmsContents/" + showContentInfo.getContentTitle());
blockBlob.downloadToFile("/storage/emulated/0/Download/LmsContents/" + showContentInfo.getContentTitle());
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (StorageException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
handler.post(() -> {
Toast.makeText(context, "Successful", Toast.LENGTH_SHORT).show();
});
});
}
Upvotes: 0
Views: 2914
Reputation: 716
Check the folder references it seems folder structure which you are providing incorrect. Just see while debugging url is correct or not .
Upvotes: 1
Reputation: 29940
One possible reason is that your blob file
is not directly under the container
. Please check in azure storage via azure portal, see if the blob file
is under some subfolders
within the container
.
If yes(for example, the blob file is b.txt
, container name is container111
, and subfolder name is sub111
), then you should change this line of code
CloudBlockBlob blockBlob = container.getBlockBlobReference("rblobName");
to
CloudBlockBlob blockBlob = container.getBlockBlobReference("sub111\b.txt");
And also, please check the connection string is correct or not.
Upvotes: 1