You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Blob Storage上传图片报prefetch>0 required错误如何解决

问题根源

  • 核心是依赖版本不兼容:你使用的Spring Boot 2.3.7.RELEASE内置的reactor-core版本为3.3.12.RELEASE,而azure-storage-blob 12.14.1要求reactor-core最低版本为3.4.x。低版本reactor的Flux.concatMap方法的prefetch参数逻辑和Azure SDK的调用逻辑不匹配,导致抛出prefetch > 0 required but it was 0异常。
  • 你尝试的同步客户端方案也报错,是因为Azure SDK的同步客户端底层也依赖reactor的异步实现,同样会触发版本不兼容问题。

解决方案

方案1:升级Spring Boot版本(推荐)

将Spring Boot版本升级到2.4.0及以上,该版本系列内置的reactor-core为3.4.x版本,可直接适配当前的Azure SDK版本:

plugins {
    id 'org.springframework.boot' version '2.4.13'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
    id 'java'
}

方案2:强制指定reactor-core版本(无需修改Spring Boot版本)

如果项目不允许升级Spring Boot,可以在gradle配置中强制覆盖reactor-core的版本为3.4.x系列:

dependencies {
    // 强制指定兼容的reactor版本
    implementation 'io.projectreactor:reactor-core:3.4.25'
    implementation 'com.azure:azure-storage-blob:12.14.1'
    implementation group: 'com.azure', name: 'azure-identity', version: '1.4.1'
}

方案3:降级Azure Blob SDK版本

如果不想修改reactor相关依赖,可以将azure-storage-blob降级到兼容reactor 3.3.x的12.11.1版本:

dependencies {
    implementation 'com.azure:azure-storage-blob:12.11.1'
    implementation group: 'com.azure', name: 'azure-identity', version: '1.4.1'
}

额外优化建议

你当前的代码是将整个文件一次性读取到内存再上传,大文件场景下容易出现OOM,建议修改为直接读取输入流的上传逻辑,以同步客户端为例:

public MyResponse<?> upload(MultipartFile file) {
    if (file.isEmpty())
        throw new BadRequestException("No File");
    String fileName = UUID.randomUUID() + file.getOriginalFilename();
    try (InputStream inputStream = file.getInputStream()) {
        BlobClient blobClient = blobContainerClient.getBlobClient(fileName);
        blobClient.upload(inputStream, file.getSize(), true);
    } catch (IOException e) {
        log.warn("文件上传失败: {}", e.getMessage());
        throw new EdutestException(ErrorType.INTERNAL_ERROR);
    }
    return new OKResponse<>("Good");
}

内容的提问来源于stack exchange,提问作者Obito Uchiha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 07:06:01