gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:51:48 25 4
gpt4 key购买 nike

我正在尝试将图像上传到 azure blob 存储。我正在使用 azure 的 java SDK。我已经引用了这些库。这是我的代码..

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

这是我的错误日志

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: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: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

最佳答案

当您的代码作为云服务运行时,您只能使用RoleEnvironment类。由于您在 Android 应用程序中运行代码,因此您无法使用此类。

如果连接设置位于配置文件中,您可能需要使用其他方法来从该配置文件中读取。

关于java - 无法将图像上传到azure blob存储android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23469945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com