60 lines
2.8 KiB
Java
60 lines
2.8 KiB
Java
package com.muyu.aliyun.bailian;
|
|
|
|
import com.aliyun.sdk.service.bailian20231229.AsyncClient;
|
|
import com.aliyun.sdk.service.bailian20231229.models.ApplyFileUploadLeaseRequest;
|
|
import com.aliyun.sdk.service.bailian20231229.models.ApplyFileUploadLeaseResponse;
|
|
import com.aliyun.sdk.service.bailian20231229.models.ApplyFileUploadLeaseResponseBody;
|
|
import com.muyu.aliyun.bailian.data.FileUploadLeaseMode;
|
|
import com.muyu.aliyun.bailian.data.fixed.UploadLeaseParamsMode;
|
|
import darabonba.core.exception.TeaException;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
@Component
|
|
@Log4j2
|
|
public class ApplyLease {
|
|
|
|
@Autowired
|
|
private AsyncClient asyncClient;
|
|
|
|
public UploadLeaseParamsMode applyFileUploadLease(FileUploadLeaseMode fileUploadLeaseModel) {
|
|
ApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = ApplyFileUploadLeaseRequest.builder()
|
|
.fileName(fileUploadLeaseModel.getFileName())
|
|
.md5(fileUploadLeaseModel.getMd5())
|
|
.sizeInBytes(fileUploadLeaseModel.getSizeInBytes())
|
|
.categoryId(fileUploadLeaseModel.getCategoryId())
|
|
.workspaceId(fileUploadLeaseModel.getWorkspaceId())
|
|
.build();
|
|
String exceptionName = "";
|
|
try {
|
|
// 复制代码运行请自行打印 API 的返回值
|
|
CompletableFuture<ApplyFileUploadLeaseResponse> applyFileUploadLeaseResponseCompletableFuture = asyncClient.applyFileUploadLease(applyFileUploadLeaseRequest);
|
|
ApplyFileUploadLeaseResponse applyFileUploadLeaseResponse = applyFileUploadLeaseResponseCompletableFuture.get();
|
|
if (applyFileUploadLeaseResponse.getStatusCode() != 200) {
|
|
throw new RuntimeException(applyFileUploadLeaseResponse.toString());
|
|
}
|
|
ApplyFileUploadLeaseResponseBody applyFileUploadLeaseResponseBody = applyFileUploadLeaseResponse.getBody();
|
|
ApplyFileUploadLeaseResponseBody.Param param = applyFileUploadLeaseResponseBody.getData().getParam();
|
|
|
|
|
|
log.info("param:「{}」", param);
|
|
return UploadLeaseParamsMode.builder()
|
|
.Url(param.getUrl())
|
|
.Method(param.getMethod())
|
|
.build();
|
|
|
|
|
|
} catch (TeaException error) {
|
|
log.error("异常名称:「{}」", error.getMessage(), error.fillInStackTrace());
|
|
throw new RuntimeException(error);
|
|
}catch (Exception exception) {
|
|
log.error("异常名称:「未知通用异常」,错误信息: {}", exception.getMessage(), exception);
|
|
throw new RuntimeException(exception);
|
|
}
|
|
}
|
|
|
|
}
|