标签: azure-sdk-for-java

使用具有有限堆的 azure-sdk-for-java 上传大文件

我们正在开发需要使用 Azure 作为文件内容存储的文档微服务。Azure Block Blob 似乎是一个合理的选择。文档服务的堆限制为 512MB ( -Xmx512m)。

我没有成功地使用有限的堆上传流式文件azure-storage-blob:12.10.0-beta.1(也在 上进行了测试12.9.0)。

尝试了以下方法:

  1. 使用从文档中复制粘贴BlockBlobClient
BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient("file").getBlockBlobClient();

File file = new File("file");

try (InputStream dataStream = new FileInputStream(file)) {
  blockBlobClient.upload(dataStream, file.length(), true /* overwrite file */);
}
Run Code Online (Sandbox Code Playgroud)

结果: java.io.IOException: mark/reset not supported - 即使文件输入流报告此功能不受支持,SDK 也会尝试使用标记/重置。

  1. 添加BufferedInputStream以减轻标记/重置问题(根据建议):
BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient("file").getBlockBlobClient();

File file = new File("file");

try (InputStream dataStream = new BufferedInputStream(new FileInputStream(file))) {
  blockBlobClient.upload(dataStream, file.length(), true /* overwrite …
Run Code Online (Sandbox Code Playgroud)

java azure azure-storage-blobs azure-java-sdk azure-sdk-for-java

5
推荐指数
1
解决办法
796
查看次数