After visiting Microsoft Cloud Camp in Brussels last week I wanted to dive into android developing by using Microsoft Azure.
I wanted to store images on a storage account, and since I didn’t use Gradle or Maven, I had some issues getting it to work. In the end, this is quick guide how I did it.
On github you can find the Microsoft Azure Storage SDK for Android. I checked out the project information on the maven-repository. I had to download the com.fasterxml.jackson.core since that was a dependency I wasn’t yet using.
On the repository URL I found the azure-storage-android-0.3.1.aar file. You need to download it and open it with a ZIP client. The classes.jar file is the library you need to put in your libs folder. I renamed it to azure-storage-android-0.3.1.jar. I also put the azure-storage-android-0.3.1-sources.jar in the libs folder.
For uploading an image to a storage account, this is a code example. Remember to execute it in an Async Task!
The image object is returned after pushing it to an Azure Mobile Service and contains the sasQueryString to authorize the upload.
String FileRef = FILEPATH + FILENAME of the file. String BaseUrl = "http://storageaccountX.blob.core.windows.net"; CloudBlobClient blobClient = new CloudBlobClient(new URI(BaseUrl); String blobName = image.ResourceName; URI uri = new URI(blobClient.getEndpoint().toString() + "/" + "containername" + "/" + blobName + "?" + image.SasQueryString); CloudBlockBlob sasBlob = new CloudBlockBlob(uri, blobClient); File fileReference = new File(FileRef); sasBlob.upload(new FileInputStream(fileReference), fileReference.length());