【Azure 存储服务】Azure Blob Storage SDK 升级失败,遇见 Unsatisfied Dependency Exception 和 Unexpected Length Exception

简介: 【Azure 存储服务】Azure Blob Storage SDK 升级失败,遇见 Unsatisfied Dependency Exception 和 Unexpected Length Exception

问题描述

在升级Java Azure Blob Storage SDK的过程中,先后遇见了 UnsatisfiedDependencyExceptionUnexpectedLengthException.

错误一:Org.springframework.beans.factory UnsatisfiedDependencyException: Error creating bean with name 'azureFileServiceImpl': Unsatisfied dependency expressed through field 'blobServiceClient'.

 

错误二:com.azure.core.exception UnexpectedLengthException Request body emitted 27183 bytes, less than the expected 31671447552 bytes.

 

 

问题解答

对于问题一:UnsatisfiedDependencyException  错误,一般来说,都是应用中引入包的版本不兼容导致,最好的办法就是升级到当前最新的版本。如把 springboot 版本升级到了2.5.6,azure storage blob版本升级到12.13.0。

 

但当问题一解决后,引发了问题二:com.azure.core.exception UnexpectedLengthException Request body emitted 27183 bytes, less than the expected 31671447552 bytes。

经过对代码中涉及到 File Length, Size等代码的调试后,发现问题所在:Azure storage Blob 由12.4.0升级到12.13.0后,获取文件的 length 发生了变化。

由旧版本的 file对象的 getTotalSpace()  变为 FileInputstream对象的 available() 。

 

代码改动截图如下:

 

 

附录一:UploadExportFile 完整代码

@Service
public class AzureServiceImpl implements AzureService{ 
    @Autowired
    private BlobServiceClient blobServiceClient;
    @Autowired
    private SysResourceMapper sysResourceMapper;
    @Autowired
    private SysOfflineExportMapper sysOfflineExportMapper;
    @Autowired
    private SysOfflineExportService sysOfflineExportService;
    @Override
    public boolean uploadExportFile(File file, SysOfflineExport export) {
        BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient("uploadblobdata");
        if(!blobContainerClient.exists()){
            createBlobContainer();
        }
        FileInputStream fileInputStream;
        try {
            fileInputStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            export.setLog(e.getMessage());
            export.setStatus(OperationStatus.Done);
            export.setResultType(ResultType.Failed);
            sysOfflineExportService.updateByUuid(export);
            return false;
        }
        //long size = file.getTotalSpace();
        long size = fileInputStream.available();
        String fileName = export.getFilenames();
        BlobClient blobClient = blobContainerClient.getBlobClient(fileName);
        blobClient.upload(fileInputStream,size);
        String blobUrl = blobClient.getBlobUrl();
        export.setDownloadurl(blobUrl);
        sysOfflineExportService.updateByUuid(export);
        if(StringUtils.isNotBlank(blobUrl)){
            export.setStatus(OperationStatus.Done);
            export.setResultType(ResultType.Success);
            sysOfflineExportService.updateByUuid(export);
            return true;
        }
        export.setStatus(OperationStatus.Done);
        export.setLog("upload file to blob failed!");
        sysOfflineExportService.updateByUuid(export);
        return false;
    }
}
相关文章
|
20天前
|
JavaScript 前端开发 API
【Azure Developer】use @azure/arm-monitor sdk 遇见 ManagedIdentityCredential authentication failed.(status code 500)
【Azure Developer】use @azure/arm-monitor sdk 遇见 ManagedIdentityCredential authentication failed.(status code 500)
|
20天前
|
存储 Java API
【Azure 存储服务】Java Storage SDK 调用 uploadWithResponse 代码示例(询问ChatGTP得代码原型后人力验证)
【Azure 存储服务】Java Storage SDK 调用 uploadWithResponse 代码示例(询问ChatGTP得代码原型后人力验证)
|
20天前
|
存储 API 开发工具
【Azure Storage Blob】如何通过.NET Azure Storage Blobs SDK获取到Blob的MD5值呢?
【Azure Storage Blob】如何通过.NET Azure Storage Blobs SDK获取到Blob的MD5值呢?
|
20天前
|
Java 开发工具
【Azure Developer】示例: 在中国区调用MSGraph SDK通过User principal name获取到User信息,如Object ID
【Azure Developer】示例: 在中国区调用MSGraph SDK通过User principal name获取到User信息,如Object ID
|
20天前
|
API 开发工具 网络架构
【Azure Developer】使用Python SDK去Azure Container Instance服务的Execute命令的疑问解释
【Azure Developer】使用Python SDK去Azure Container Instance服务的Execute命令的疑问解释
【Azure Developer】使用Python SDK去Azure Container Instance服务的Execute命令的疑问解释
|
20天前
|
开发工具 iOS开发 容器
【Azure Blob】关闭Blob 匿名访问,iOS Objective-C SDK连接Storage Account报错
【Azure Blob】关闭Blob 匿名访问,iOS Objective-C SDK连接Storage Account报错
|
20天前
|
消息中间件 开发工具
【Azure Service Bus】Service Bus SDK 抛出 ERROR c.a.c.a.i.ActiveClientTokenManager - Error is transient. Rescheduling authorization task at interval 1079000 ms.
【Azure Service Bus】Service Bus SDK 抛出 ERROR c.a.c.a.i.ActiveClientTokenManager - Error is transient. Rescheduling authorization task at interval 1079000 ms.
|
20天前
|
开发工具
【Azure Event Hub】解决Event Hub SDK出现无法识别 com.azure.core.client.traits.TokenCredentialTrait 错误
【Azure Event Hub】解决Event Hub SDK出现无法识别 com.azure.core.client.traits.TokenCredentialTrait 错误
|
16天前
|
JavaScript 前端开发 Java
[Android][Framework]系统jar包,sdk的制作及引用
[Android][Framework]系统jar包,sdk的制作及引用
34 0
|
1月前
|
开发工具 Android开发
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file
132 4
解决Android运行出现NDK at /Library/Android/sdk/ndk-bundle did not have a source.properties file

热门文章

最新文章