azure - 为 azure blob 添加 Pom 依赖项将我的 REST API 响应从 JSON 更改为 XML
问题描述
我有一个带有 REST API 的 Web 应用程序,它工作正常,返回 JSON 响应,完全没有问题。
现在我正在尝试添加 azure blob 服务以将 blob 文件上传到我的 azure 帐户。
一旦我为 azure blob 添加了 maven 依赖项,我现有的 REST API 就开始返回 XML 响应,从而破坏了我的整个应用程序。
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.6.0</version>
</dependency>
有人遇到过这个问题吗?删除此依赖项可解决问题,但我将无法连接到 Azure 云。
解决方案
即使添加了依赖项,为什么不使用 Java SDK?
如果您仍想使用PUT BLOB等 REST API ,您可以设置Content-Type
为application/json
. 使用共享密钥访问时,还需要在“stringToSign”中添加Content-Type。您可以使用 C#参考此问题。
StringToSign = VERB + "\n" +
Content-Encoding + "\n" +
Content-Language + "\n" +
Content-Length + "\n" +
Content-MD5 + "\n" +
Content-Type + " \n" +
日期 + "\n" +
If-Modified-Since + "\n" +
If-Match + "\n" +
If-None-Match + "\n" +
If-Unmodified-Since + "\ n" +
范围 + "\n" +
CanonicalizedHeaders +
CanonicalizedResource;
使用SDK将本地文件上传到 blob 的演示:
String accountName = "";
String accountKey = "";
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net", accountName);
BlobServiceClient storageClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(credential).buildClient();
BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient("mycontainer");
BlobClient blobClient = blobContainerClient.getBlobClient("myblockblob");
blobClient.uploadFromFile("local-file.jpg");
推荐阅读
- python-3.x - 输出文件更长?
- android-studio - 从 expo 转换为 react-native-cli 后要使用的命令
- google-cloud-platform - Stackdriver 是区域本地的吗?
- javascript - 如何使用自定义 Vue 插件
- sql - 如果在特定时间段内没有对列进行任何更改,是否有办法生成自动电子邮件?
- java - 如何创建一个将 isSecure 标志设置为 false 的 org.openqa.selenium.Cookie
- geoserver - 有没有办法在 GeoTIFF 文件中包含旋转元数据?
- excel - 关于如何根据多个标准对值求和的意见
- tensorflow - 使用 Keras LSTM 层处理具有不同序列长度的示例
- apache-spark - 如何使用 Apache Spark 读取巨大的单行 (100GB)