Android - 在 Azure 容器中上传图像

标签 android azure blob

我使用以下代码从 android 将图像上传到 azure 的存储容器中。它在“//Create the blob client”行上抛出错误。一些java.lang.verifyError。我已尝试解决此错误,但找不到任何解决方案。

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());

这是我遇到的错误:

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)

最佳答案

我遇到了同样的问题,很可能是您正在使用的依赖项。利用下面的库可以解决 Android 应用程序开发的问题。

一旦我使用了这个,一切就都正常了。 https://github.com/Azure/azure-storage-android

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

关于Android - 在 Azure 容器中上传图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25338414/

相关文章:

android - 我想从 Android 应用程序打开日历应用程序

android - ListView 中的复选框样式不正确

android - 按下启动另一个 Activity 的按钮时应用程序崩溃

azure - 用于生成和查看 Azure block Blob 和 Azure 文件共享的 SAS(共享访问签名)的工具或使用示例

azure - 在 Azure Blob 存储中存储文件组

database - Yii2 显示存储在 BLOB 数据库字段中的图像

c# - 禁用 Azure Blob 直接下载

android - 删除 Realm 数据库对象,但即使所有对象都为空, Realm 文件大小保持不变。随着时间的推移变得太大了

rest - 在 Azure 移动应用/服务中使用 TableController

java - 使用 BLOB 或 TEXT/CLOB 在字段中保存 HTML 数据