gpt4 book ai didi

java - 如何直接从Spring Boot应用程序将文件上传到azure blob存储,而不将文件放入内存(缓冲内存)

转载 作者:行者123 更新时间:2023-12-05 06:08:03 24 4
gpt4 key购买 nike

我有 spring boot 应用程序,它将上传 zip 文件(大小> 250MB)到 azure blob 存储,如果文件没有直接上传到 azure,那么它将使用内存空间,这可能会导致内存大小不足多个请求。因此,请给我一些引用或代码片段来解决我的问题。谢谢。

最佳答案

如果您想直接上传文件到Azure Blob,请引用以下步骤

  1. SDK
<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";
    }

    enter image description here

    关于java - 如何直接从Spring Boot应用程序将文件上传到azure blob存储,而不将文件放入内存(缓冲内存),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65198768/

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