Azure / azure-storage-java

Microsoft Azure Storage Library for Java
https://docs.microsoft.com/en-us/java/api/overview/azure/storage
MIT License
189 stars 163 forks source link

File upload and download not working on a device #522

Open DeveloperBeginner opened 4 years ago

DeveloperBeginner commented 4 years ago

Which service(blob, file, queue, table) does this issue concern?

Issue with blob and file

Which version of the SDK was used?

OS and version used: Android 6.0.1

Java runtime used: 1.8.0

SDK version used: IoT Device client 1.19.0

What problem was encountered?

I am using the iot device client sdk in my Android application. Two of the many devices in the client location are not able to download files from blob storage. I only have the first few characters of the error logs:

An unknown failure occurred : failed to connect to <storage account name>

File uploads are also failing in these devices. Unfortunately I do not have the error logs.

However, I noticed that device telemetry events are successfully sent from these two devices.

Please help me find out under which conditions file upload/download fails with this error message. Also help me find a solution to this issue.

Code sample exhibiting the issue:

Gradle file:

dependencies {
    implementation (group: 'com.microsoft.azure.sdk.iot', name: 'iot-device-client', version: '1.19.0'
    {
        exclude module: 'azure-storage'
    }
    implementation ('com.microsoft.azure.android:azure-storage-android:2.0.0@aar')
}

File upload :

 deviceClient.uploadToBlobAsync(file.getName(), inputStream, streamLength,
                new FileUploadStatusCallBack(), callbackContext);

File download:

 CloudStorageAccount storageAccount = CloudStorageAccount
            .parse(storageAccountConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlockBlob blob = container.getBlockBlobReference(blobReference);
 if (blob.exists()) {
       blob.downloadAttributes();
       long blobSize = blob.getProperties().getLength();
       final ByteArrayOutputStream blobStream = new ByteArrayOutputStream();
       blob.download(blobStream);
}
DeveloperBeginner commented 4 years ago

I observed the issue during file download today and have captured the Exception logs as follows. File upload is however working well.

com.microsoft.azure.storage.StorageException: isConnected failed: ETIMEDOUT (Connection timed out)

com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry ExecutionEngine.java:206
com.microsoft.azure.storage.blob.CloudBlob.exists CloudBlob.java:1831
com.microsoft.azure.storage.blob.CloudBlob.exists CloudBlob.java:1818
com.microsoft.azure.storage.blob.CloudBlob.exists CloudBlob.java:1793
com.xxxxxxx.xxxxxxx.FileDownloadTask.download FileDownloadTask.java:98
com.xxxxxxx.xxxxxxx.FileDownloadTask.run FileDownloadTask.java:76
java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java:1113
java.util.concurrent.ThreadPoolExecutor$Worker.run ThreadPoolExecutor.java:588
java.lang.Thread.run Thread.java:818

A small code snippet of my class FileDownloadTask is as follows

        CloudBlockBlob blob;
        if (!TextUtils.isEmpty(mBlobDirectoryReference)) {
            blob = container.getDirectoryReference(mBlobDirectoryReference).
                    getBlockBlobReference(mBlobReference);
        } else {
            blob = container.getBlockBlobReference(mBlobReference);
        }

        if (blob.exists()) { //line number 98 in FileDownloadTask
            ...
        }

So the exception is seen for the line

if (blob.exists())

When do we see this exception? My device has internet connectivity. The blob directory and file referred to also exists and is valid.

nishanthvasu commented 1 year ago

Hi Team,

@emgerner-msft @esummers-msft @bryant1410 @asorrin-msft @pemari-msft @dadoonet @m-moris

Any updates on this issue?

dadoonet commented 1 year ago

@nishanthvasu Why are you pinging me on an issue I'm not involved in?

nishanthvasu commented 1 year ago

Hi @dadoonet ,

I am just trying to reach to all contributors to get any update on this issue, since its been open for long time and blocking to download files using this SDK in production. I am not aware that you were not a part of this.