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

    Question

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

    Code:
         public class UploadFile {

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

    try
    {
       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.
       e.printStackTrace();
    }


    }
        }


    Sas Uri Generated is:

         https://assetservice.blob.core.windows.net/org66/7594787459-5373-4485-a5ad-8b8a9b5af62c/Input/834793kfhreh-ee2a-4c80-a766-146fc139f2c4.hlkx?sv=2013-08-15&sr=b&sig=jkdhfueiwhdjscnkljshchcvdhcdsnc&se=2016-07-13T18%3A18%3A09Z&sp=w

    I am getting error message:

        java.io.IOException
    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

Answers