[Java] Unable to upload file to SAS URI using java and Storage library RRS feed

  • Question

  • Here I am using Microsoft Storage Library, But I am not able to upload my file to Azure storage

         public class UploadFile {

    public static void uploadFile(String sasURL,String filePath,String submissionGuid) throws MalformedURLException, URISyntaxException
    URI sasUrl = new URI(sasURL);

       CloudBlobContainer container = new CloudBlobContainer(sasUrl);
       CloudBlockBlob blob = container.getBlockBlobReference(sasUrl.getPath());
       File source = new File(filePath);

       blob.upload(new FileInputStream(source), source.length());
    catch (Exception e)
       // Output the stack trace.


    Sas Uri Generated is:


    I am getting error message:

    at com.microsoft.azure.storage.core.Utility.initIOException(Utility.java:569)
    at com.microsoft.azure.storage.blob.BlobOutputStream.writeBlock(BlobOutputStream.java:444)
    at com.microsoft.azure.storage.blob.BlobOutputStream.access$000(BlobOutputStream.java:53)
    at com.microsoft.azure.storage.blob.BlobOutputStream$1.call(BlobOutputStream.java:388)
    at com.microsoft.azure.storage.blob.BlobOutputStream$1.call(BlobOutputStream.java:385)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

    and authorization error as well, even though sasuri being passed has all the required parameters in it:

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
        Caused by: com.microsoft.azure.storage.StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
    at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:89)
    at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305)
    at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:175)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.uploadBlockInternal(CloudBlockBlob.java:904)
    at com.microsoft.azure.storage.blob.CloudBlockBlob.uploadBlock(CloudBlockBlob.java:876)
    at com.microsoft.azure.storage.blob.BlobOutputStream.writeBlock(BlobOutputStream.java:438)
    ... 9 more

    I think I dont understand the part where i should pass Blob-container-name as i even tried passing org66 but it didnt work for me.

    Any suggestion and an attempt to make me understand the part of SAS URI Generated is really appreciated .
    I am also confused on the part as in what is my container name etc.

    Stackoverflow link: http://stackoverflow.com/questions/38383264/unable-to-upload-file-to-sas-uri

    Thursday, July 14, 2016 8:08 PM


  • Hi,

    Thank you for posting here.

    The sas url is directly for Blob. You can directly use the code below to get the blob object for uploading.

    CloudBlockBlob blob = new CloudBlockBlob(sasUrl);

    Best Regards,

    Peter Pan

    • Proposed as answer by vikranth s Friday, July 15, 2016 8:27 AM
    • Marked as answer by Mikasa Ackerman Friday, July 15, 2016 3:49 PM
    Friday, July 15, 2016 7:27 AM