I know that there is a library for downloading a file using Azure storage. I have to refer to the same.
But they do not provide information on how to use SAS with this. I have an account name and sas url to access and upload the file there. But I do not know how to use this to upload a file.
If I use the above library, it shows me an invalid storage connection string, because I do not pass the key in it (which is not required for sas). So I am confused how can I upload a file.
I mean this documentation also for downloading files using sas. but not getting the proper steps for this. They made a demo for their Windows application. I want to have this in Android using SAS.
Refresh
I tried with the code below with a link to a console application created by Azure to test and access SAS.
try { //Try performing container operations with the SAS provided. //Return a reference to the container using the SAS URI. //CloudBlockBlob blob = new CloudBlockBlob(new StorageUri(new URI(sas))); String[] str = userId.split(":"); String blobUri = "https://myStorageAccountName.blob.core.windows.net/image/" + str[1] + "/story/" + storyId + "/image1.jpg" + sas.toString().replaceAll("\"",""); Log.d(TAG,"Result:: blobUrl 1 : "+blobUri); CloudBlobContainer container = new CloudBlobContainer(new URI(blobUri)); Log.d(TAG,"Result:: blobUrl 2 : "+blobUri); CloudBlockBlob blob = container.getBlockBlobReference("image1.jpg"); String filePath = postData.get(0).getUrl().toString(); /*File source = new File(getRealPathFromURI(getApplicationContext(),Uri.parse(filePath))); // File path blob.upload(new FileInputStream(source), source.length());*/ Log.d(TAG,"Result:: blobUrl 3 : "+blobUri); //blob.upload(new FileInputStream(source), source.length()); //blob.uploadText("Hello this is testing..."); // Upload text file Log.d(TAG, "Result:: blobUrl 4 : " + blobUri); Log.d(TAG, "Write operation succeeded for SAS " + sas); response = "success"; //Console.WriteLine(); } catch (StorageException e) { Log.d(TAG, "Write operation failed for SAS " + sas); Log.d(TAG, "Additional error information: " + e.getMessage()); response = e.getMessage(); } catch (FileNotFoundException e) { e.printStackTrace(); response = e.getMessage(); } catch (IOException e) { e.printStackTrace(); response = e.getMessage(); } catch (URISyntaxException e) { e.printStackTrace(); response = e.getMessage(); } catch (Exception e){ e.printStackTrace(); response = e.getMessage(); }
Now when I upload the text only it tells me the error below
The server failed to authenticate the request. Verify that the authorization header value is configured correctly, including the signature.
Now my requirement is to upload an image file. Therefore, when I uncomment the code for loading the image file, it does not produce any error, but does not even load the image file.
android azure azure-storage azure-storage-blobs azure-mobile-services
iDroid Explorer
source share