【发布时间】:2020-12-08 12:16:15
【问题描述】:
我有 Spring Boot 应用程序,它会将 zip 文件(大小 > 250MB)上传到 azure blob 存储,如果文件不直接上传到 azure,那么它将使用内存空间,这可能会导致内存大小不足多个请求。所以,请给我一些参考或代码 sn-p 来解决我的问题。谢谢。
【问题讨论】:
标签: java azure spring-boot azure-blob-storage
我有 Spring Boot 应用程序,它会将 zip 文件(大小 > 250MB)上传到 azure blob 存储,如果文件不直接上传到 azure,那么它将使用内存空间,这可能会导致内存大小不足多个请求。所以,请给我一些参考或代码 sn-p 来解决我的问题。谢谢。
【问题讨论】:
标签: java azure spring-boot azure-blob-storage
如果要直接将文件上传到 Azure blob,请参考以下步骤
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.6.0</version>
</dependency
@PostMapping(path = "/upload")
public String uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
String constr="";
BlobContainerClient container = new BlobContainerClientBuilder()
.connectionString(constr)
.containerName("upload")
.buildClient();
BlobClient blob=container.getBlobClient(file.getOriginalFilename());
blob.upload(file.getInputStream(),file.getSize(),true);
return "ok";
}
【讨论】: