简体   繁体   English

Android-在Azure容器中上传图像

[英]Android - Upload Image in a Azure Container

I have used the following code to upload image in a storage container in azure from android. 我已使用以下代码从android中以天蓝色将图像上传到存储容器中。 It throws the error on "// Create the blob client" line. 它在“ //创建Blob客户端”行上引发错误。 some java.lang.verifyError. 一些java.lang.verifyError。 I have searched to solve this error but i can't find any solution. 我已搜索解决此错误,但找不到任何解决方案。

String connectionString = "DefaultEndpointsProtocol=https;AccountName=StorageAccountName;AccountKey=StorageAccountKey"

CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString);

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

// Get a reference to a container
// The container name must be lower case
CloudBlobContainer container = blobClient.getContainerReference("images");

// Create the container if it does not exist
container.createIfNotExists();

// Create a permissions object
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();

// Include public access in the permissions object
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);

// Set the permissions on the container
container.uploadPermissions(containerPermissions);

// Create or overwrite the "myimage.jpg" blob with contents from a local file
CloudBlockBlob blob = container.getBlockBlobReference("myimageYdolo.jpg");
File source = new File(currImageURI.toString());
blob.upload(new FileInputStream(source), source.length());

Here is the error i have got: 这是我得到的错误:

08-16 14:48:15.045: W/dalvikvm(5579): VFY: unable to find exception handler at addr 0x2b
08-16 14:48:15.045: W/dalvikvm(5579): VFY:  rejected Lcom/microsoft/azure/storage/ServiceClient;.uploadServicePropertiesImpl (Lcom/microsoft/azure/storage/ServiceProperties;Lcom/microsoft/azure/storage/RequestOptions;Lcom/microsoft/azure/storage/OperationContext;Z)Lcom/microsoft/azure/storage/core/StorageRequest;
08-16 14:48:15.045: W/dalvikvm(5579): VFY:  rejecting opcode 0x0d at 0x002b
08-16 14:48:15.045: W/dalvikvm(5579): VFY:  rejected Lcom/microsoft/azure/storage/ServiceClient;.uploadServicePropertiesImpl (Lcom/microsoft/azure/storage/ServiceProperties;Lcom/microsoft/azure/storage/RequestOptions;Lcom/microsoft/azure/storage/OperationContext;Z)Lcom/microsoft/azure/storage/core/StorageRequest;
08-16 14:48:15.045: W/dalvikvm(5579): Verifier rejected class Lcom/microsoft/azure/storage/ServiceClient;
08-16 14:48:15.045: D/AndroidRuntime(5579): Shutting down VM
08-16 14:48:15.045: W/dalvikvm(5579): threadid=1: thread exiting with uncaught exception (group=0x41dc6ba8)
08-16 14:48:15.045: E/AndroidRuntime(5579): FATAL EXCEPTION: main
08-16 14:48:15.045: E/AndroidRuntime(5579): Process: com.example.azuretry, PID: 5579
08-16 14:48:15.045: E/AndroidRuntime(5579): java.lang.VerifyError: com/microsoft/azure/storage/ServiceClient
08-16 14:48:15.045: E/AndroidRuntime(5579):     at com.microsoft.azure.storage.CloudStorageAccount.createCloudBlobClient(CloudStorageAccount.java:715)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at com.example.azuretry.FullscreenActivity.onActivityResult(FullscreenActivity.java:144)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at android.app.Activity.dispatchActivityResult(Activity.java:5423)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3347)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3394)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at android.app.ActivityThread.access$1300(ActivityThread.java:135)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at android.os.Handler.dispatchMessage(Handler.java:102)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at android.os.Looper.loop(Looper.java:136)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at android.app.ActivityThread.main(ActivityThread.java:5001)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at java.lang.reflect.Method.invokeNative(Native Method)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at java.lang.reflect.Method.invoke(Method.java:515)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
08-16 14:48:15.045: E/AndroidRuntime(5579):     at dalvik.system.NativeStart.main(Native Method)

I had an identical issue, it is most likely the dependency that you are using. 我有一个相同的问题,很可能是您使用的依赖项。 Utilizing the library below resolves the issue for Android App development. 利用下面的库可解决Android App开发的问题。

Once I used this everything worked. 一旦使用了此功能,一切都会正常。 https://github.com/Azure/azure-storage-android https://github.com/Azure/azure-storage-android

dependencies {
    compile 'com.microsoft.azure.android:azure-storage-android:0.3.0@aar'
}

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

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