none
Android - Upload Image in a Container

    Question

  • String connectionString = "DefaultEndpointsProtocol=https;AccountName=StorageAccountName;AccountKey=StorageAccountKey"


    CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString);

                            // Create the blob client
                            CloudBlobClient blobClient = storageAccount.createCloudBlobClient();

                            // Get a reference to a container
                            // The container name must be lower case
                            CloudBlobContainer container = blobClient.getContainerReference("images");

                            // Create the container if it does not exist
                            container.createIfNotExists();

                            // Create a permissions object
                            BlobContainerPermissions containerPermissions = new BlobContainerPermissions();

                            // Include public access in the permissions object
                            containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);

                            // Set the permissions on the container
                            container.uploadPermissions(containerPermissions);

                            // Create or overwrite the "myimage.jpg" blob with contents from a local file
                            CloudBlockBlob blob = container.getBlockBlobReference("myimageYdolo.jpg");
                            File source = new File(currImageURI.toString());
                            blob.upload(new FileInputStream(source), source.length());

     I have used the above code to upload image in a storage container in azure from android. It throws the error on "// Create the blob client" line. some java.lang.verifyError. I have searched to solve this error but i can't find any solution.

                                                                                                                                        
    Saturday, August 16, 2014 7:11 AM

Answers

  • Hi Veerasuthan,

    For this issue, I suggest you could try the code below.

    import com.microsoft.azure.storage.*;
    import com.microsoft.azure.storage.blob.*;
    
    public class BlobSample {
        public static final String storageConnectionString =
            "DefaultEndpointsProtocol=http;"
            + "AccountName=your_account_name;"
            + "AccountKey= your_account_key";
    
        public static void main(String[] args) {
     
                CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
                CloudBlobClient serviceClient = account.createCloudBlobClient();
    
                // Container name must be lower case.
                CloudBlobContainer container = serviceClient.getContainerReference("myimages");
                container.createIfNotExists();
    
    -----------
    }
    }

    Aslo, you could refer to this code sample (https://github.com/Azure/azure-storage-java). Please try it.

    Any results, please let me know free.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, August 22, 2014 9:24 AM
    Moderator

All replies

  • Hi,

    Please use the following code in "//Retrieve storage account from connection string" step and check if it able to create the blob client

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("connectionString"));

    Regards,

    Manu Rekhar

    Saturday, August 16, 2014 7:41 AM
    Moderator
  • Hi,

      Thanks for reply. 

       I can't use this line

    CloudConfigurationManager.GetSetting("");

    in android.

    there is no such class in azure-storage.jar file in android


    • Edited by govindrajan Saturday, August 16, 2014 8:35 AM
    Saturday, August 16, 2014 8:33 AM
  • Hi Veerasuthan,

    For this issue, I suggest you could try the code below.

    import com.microsoft.azure.storage.*;
    import com.microsoft.azure.storage.blob.*;
    
    public class BlobSample {
        public static final String storageConnectionString =
            "DefaultEndpointsProtocol=http;"
            + "AccountName=your_account_name;"
            + "AccountKey= your_account_key";
    
        public static void main(String[] args) {
     
                CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
                CloudBlobClient serviceClient = account.createCloudBlobClient();
    
                // Container name must be lower case.
                CloudBlobContainer container = serviceClient.getContainerReference("myimages");
                container.createIfNotExists();
    
    -----------
    }
    }

    Aslo, you could refer to this code sample (https://github.com/Azure/azure-storage-java). Please try it.

    Any results, please let me know free.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, August 22, 2014 9:24 AM
    Moderator