Quantcast
Channel: Azure Virtual Machines forum
Viewing all articles
Browse latest Browse all 12545

Not able to Upload/download files from blob through Ubuntu VM command line

$
0
0

Hi,

I have written a code in java to upload/download files from blob storage using REST API. I have created the jar file including external libraries from win azure. It runs successfully when I run it through windows command prompt. I want to run the jar file on my Ubuntu VM and access my blob storage from there.

For some reason, I am getting problem while uploading/downloading files through VM.

Earlier I thought that there could be problem with the path that I am giving. But I have verified that the path that I am passing through console is correct. (/dev/shm/testfiles/filename.jpg)

I am able to access my storage but there is a problem while uploading/downloading files from blob.

I also tried giving the path in the code itself but it is not working. Here is the code for upload-

public static void MyUploadBlob(String containername, String containerSAS, CloudBlobClient blobClient, String[] fileList, int iter)
               throws URISyntaxException, StorageException, FileNotFoundException, IOException
          {
              String blobName = fileList[iter];  // contains file name to be uploaded in the blob
              String localFileName = "/dev/shm/testfiles/" + fileList[iter];  // Path and name of the local file.

              // Append the container name, blob name, and
              // shared access signature to the URI.
              URI uri = new URI(blobClient.getEndpoint().toString() + "/" +
                                containername + "/" +
                                blobName +"?" +
                                containerSAS);

              // Create a blob using the URI that contains the shared access signature.
              CloudBlockBlob sasBlob = new CloudBlockBlob(uri, blobClient);

              // Get a file reference to the local file.
              File fileReference = new File (localFileName);
              
              // Upload the file to the blob.
              sasBlob.upload(new FileInputStream(fileReference), fileReference.length());
              
          }

Any help will be greatly appreciated.

Thanks

ERROR -

The shared access signature was created.
java.io.IOException
        at com.microsoft.windowsazure.services.core.storage.utils.Utility.initIO                                                                                        Exception(Utility.java:563)
        at com.microsoft.windowsazure.services.blob.client.BlobOutputStream$1.ca                                                                                        ll(BlobOutputStream.java:377)
        at com.microsoft.windowsazure.services.blob.client.BlobOutputStream$1.ca                                                                                        ll(BlobOutputStream.java:361)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:47                                                                                        1)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.                                                                                        java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor                                                                                        .java:615)
        at java.lang.Thread.run(Thread.java:722)
Caused by: com.microsoft.windowsazure.services.core.storage.StorageException: Se                                                                                        rver failed to authenticate the request. Make sure the value of Authorization he                                                                                        ader is formed correctly including the signature.
        at com.microsoft.windowsazure.services.core.storage.StorageException.tra                                                                                        nslateException(StorageException.java:104)
        at com.microsoft.windowsazure.services.core.storage.utils.implementation                                                                                        .StorageOperation.materializeException(StorageOperation.java:143)
        at com.microsoft.windowsazure.services.core.storage.utils.implementation                                                                                        .ExecutionEngine.executeWithRetry(ExecutionEngine.java:121)
        at com.microsoft.windowsazure.services.blob.client.CloudBlockBlob.upload                                                                                        BlockInternal(CloudBlockBlob.java:639)
        at com.microsoft.windowsazure.services.blob.client.CloudBlockBlob.upload                                                                                        Block(CloudBlockBlob.java:578)
        at com.microsoft.windowsazure.services.blob.client.BlobOutputStream$1.ca                                                                                        ll(BlobOutputStream.java:365)
        ... 9 more
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.                                                                                        java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces                                                                                        sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at com.simontuffs.onejar.Boot.run(Boot.java:306)
        at com.simontuffs.onejar.Boot.main(Boot.java:159)


Viewing all articles
Browse latest Browse all 12545

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>