简体   繁体   English

无法将图像上传到azure blob存储android

[英]Unable to upload image to azure blob storage android

I m trying to upload an image to azure blob storage. 我试图将图像上传到azure blob存储。 I am using java SDK for azure.I have referenced the libraries. 我正在使用java SDK for azure.I引用了这些库。 Here is my code.. 这是我的代码..

public void uploadImage(View view) {
    // Do something in response to button click
    try
     {
     String storageConnectionString = 
                RoleEnvironment.getConfigurationSettings().get("StorageConnectionString");
        CloudStorageAccount storageAccount =
                CloudStorageAccount.parse(storageConnectionString);

            // Create the blob client
            CloudBlobClient blobClient = storageAccount.createCloudBlobClient();

            // Retrieve reference to a previously created container
            CloudBlobContainer container = blobClient.getContainerReference("classifieds");

            // Create or overwrite the "myimage.jpg" blob with contents from a local file
            CloudBlockBlob blob = container.getBlockBlobReference("myimage.png");
             InputStream ims = getAssets().open("myimage.png");

            int len =ims.available();
            blob.upload(ims,(long)ims.available());
     }
     catch(Exception ex)
     {
         System.out.println(ex);
     }
}

Here is my error log 这是我的错误日志

05-05 15:34:25.295: E/Trace(5195): error opening trace file: No such file or directory (2) 05-05 15:34:26.105: I/dalvikvm(5195): Could not find method com.microsoft.windowsazure.serviceruntime.RoleEnvironment.getConfigurationSettings, referenced from method com.example.azuresample.MainActivity.uploadImage 05-05 15:34:26.105: W/dalvikvm(5195): VFY: unable to resolve static method 8441: Lcom/microsoft/windowsazure/serviceruntime/RoleEnvironment;.getConfigurationSettings ()Ljava/util/Map; 05-05 15:34:25.295:E / Trace(5195):错误打开跟踪文件:没有这样的文件或目录(2)05-05 15:34:26.105:I / dalvikvm(5195):找不到方法com .microsoft.windowsazure.serviceruntime.RoleEnvironment.getConfigurationSettings,从方法com.example.azuresample.MainActivity.uploadImage引用05:34:26.105:W / dalvikvm(5195):VFY:无法解析静态方法8441:Lcom / microsoft / windowsazure / serviceruntime / RoleEnvironment; .getConfigurationSettings()Ljava / util / Map; 05-05 15:34:26.105: D/dalvikvm(5195): VFY: replacing opcode 0x71 at 0x0000 05-05 15:34:26.550: D/gralloc_goldfish(5195): Emulator without GPU emulation detected. 05-05 15:34:26.105:D / dalvikvm(5195):VFY:将代码0x71替换为0x0000 05-05 15:34:26.550:D / gralloc_goldfish(5195):未检测到GPU仿真的仿真器。 05-05 15:34:34.254: D/AndroidRuntime(5195): Shutting down VM 05-05 15:34:34.254: W/dalvikvm(5195): threadid=1: thread exiting with uncaught exception (group=0x40a13300) 05-05 15:34:34.285: E/AndroidRuntime(5195): FATAL EXCEPTION: main 05-05 15:34:34.254:D / AndroidRuntime(5195):关闭VM 05-05 15:34:34.254:W / dalvikvm(5195):threadid = 1:线程退出未捕获异常(组= 0x40a13300)05 -05 15:34:34.285:E / AndroidRuntime(5195):致命异常:主要

You can only use RoleEnvironment class when your code is running as a Cloud Service . 当代码作为Cloud Service运行时,您只能使用RoleEnvironment类。 Since you're running the code in an Android application, this class is not available to you. 由于您在Android应用程序中运行代码,因此您无法使用此类。

If the connection settings are in a configuration file, you may want to resort to another methods to read from that configuration file. 如果连接设置位于配置文件中,您可能需要使用其他方法从该配置文件中读取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM