2

我遵循了这些步骤,希望让本地主机上的存储模拟器正常工作。

我正在使用 Windows 8 RTM。

  1. 下载Eclipse并将其复制到 Program Files。
  2. 安装 Java JDK 7。
  3. 已安装 Azure SDK
  4. 为 Eclipse安装了 Azure插件
  5. 从“开始”屏幕启动存储模拟器。
  6. 创建了一个Java项目。
  7. 在此项目的 Azure 构建路径中添加了外部jar 。
  8. 写了这个简单的示例代码:

    import com.microsoft.windowsazure.services.blob.client.CloudBlobClient;
    import com.microsoft.windowsazure.services.blob.client.CloudBlobContainer;
    import com.microsoft.windowsazure.services.core.storage.CloudStorageAccount;
    
    public class AzureStore {
        public static final String storageConnectionString = "DefaultEndpointsProtocol=http;"
                + "UseDevelopmentStorage=true;"
                + "AccountName=devstoreaccount1;"
                + "BlobEndpoint=http://127.0.0.1:10000;"
                + "AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
    
        public static void main(String[] args) throws Exception {
            // Retrieve storage account from connection-string
            CloudStorageAccount storageAccount = CloudStorageAccount
                    .parse(storageConnectionString);
    
            // 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("tweet");
    
            try {
                // Create the container if it does not exist
                System.out.println(container.createIfNotExist());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    

它给出了以下例外:

com.microsoft.windowsazure.services.core.storage.StorageException: The value for one of the HTTP headers is not in the correct format.
at com.microsoft.windowsazure.services.core.storage.StorageException.translateException(StorageException.java:104)
at com.microsoft.windowsazure.services.blob.client.CloudBlobContainer$2.execute(CloudBlobContainer.java:334)
at com.microsoft.windowsazure.services.blob.client.CloudBlobContainer$2.execute(CloudBlobContainer.java:291)
at com.microsoft.windowsazure.services.core.storage.utils.implementation.ExecutionEngine.executeWithRetry(ExecutionEngine.java:110)
at com.microsoft.windowsazure.services.blob.client.CloudBlobContainer.createIfNotExist(CloudBlobContainer.java:339)
at com.microsoft.windowsazure.services.blob.client.CloudBlobContainer.createIfNotExist(CloudBlobContainer.java:257)
at AzureStore.main(AzureStore.java:26)

在这一点上我很困惑,因为可能是错的。有人能帮我吗?

4

2 回答 2

0

更多关于URI

看看下面是否适合你。

URI BlobEndPoint = new URI("http://127.0.0.1:10000/devstoreaccount1");

CloudBlobClient bClient = new CloudBlobClient(BlobEndPoint, new StorageCredentialsAccountAndKey(AccountName,
                AccountSecurityKey));
于 2012-09-25T04:25:10.887 回答
0

我认为错误是由于 API 中的存储服务版本不正确而发生的。在您的代码中,您尝试在开发存储中创建一个 blob 容器。“x-ms-version”请求标头值作为“2012-02-12”发送,虽然是最新的,但仍不受开发存储支持。开发存储仍支持“2011-08-18”。

如果您针对云存储尝试您的代码,您应该能够创建该 blob 容器。

如果您只是针对开发存储进行开发,您可以做的一件事是从 GitHub (https://github.com/WindowsAzure/azure-sdk-for-java/downloads) 下载源代码并修改以下行Constants.java 中的代码

public static final String TARGET_STORAGE_VERSION = "2012-02-12";

public static final String TARGET_STORAGE_VERSION = "2011-08-18";

and compile the source code again. This may break some new functionality introduced in the latest service release (like asynchronous copy blobs etc.)

Other alternative is to wait out for the new SDK to come out and hope that the emulator in that version support the latest storage service version.

于 2012-09-25T08:29:39.777 回答