feat: 上传素材接口,前端改传url
This commit is contained in:
parent
e888da137e
commit
96646cf5ed
|
|
@ -41,12 +41,12 @@ public class ByteAssetApiController extends BaseController {
|
|||
@PostMapping(value = "/createAsset", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@ApiOperation("CreateAsset:先将文件上传至对象存储,再调用 CreateAsset")
|
||||
public AjaxResult<CreateAssetResponse> createAsset(
|
||||
@ApiParam(value = "素材文件", required = true) @RequestPart("file") MultipartFile file,
|
||||
@ApiParam(value = "素材url", required = true) @RequestParam("url") String url,
|
||||
@ApiParam(value = "所属素材组 id(GroupId)", required = true) @RequestParam("groupId") String groupId,
|
||||
@ApiParam(value = "素材类型:Image / Video / Audio", required = true) @RequestParam("assetType") String assetType,
|
||||
@ApiParam(value = "素材名称,可选") @RequestParam(value = "name", required = false) String name) {
|
||||
try {
|
||||
return AjaxResult.success(byteAssetService.createAsset(file, groupId, assetType, name));
|
||||
return AjaxResult.success(byteAssetService.createAsset(url, groupId, assetType, name));
|
||||
} catch (Exception e) {
|
||||
log.error("创建素材时发生异常", e);
|
||||
return AjaxResult.error(e.getMessage());
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public interface IByteAssetService {
|
|||
/**
|
||||
* 先将文件上传至对象存储得到公网 URL,再调用 CreateAsset。
|
||||
*/
|
||||
CreateAssetResponse createAsset(MultipartFile file, String groupId, String assetType, String name) throws Exception;
|
||||
CreateAssetResponse createAsset(String url, String groupId, String assetType, String name) throws Exception;
|
||||
|
||||
ListAssetsResponse listAssets(ListAssetsRequest request) throws IOException;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,17 +32,13 @@ public class ByteAssetService extends BaseByteApiService implements IByteAssetSe
|
|||
private static final String ACTION_DELETE_ASSET = "DeleteAsset";
|
||||
|
||||
@Override
|
||||
public CreateAssetResponse createAsset(MultipartFile file, String groupId, String assetType, String name) throws Exception {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new IllegalArgumentException("上传文件不能为空");
|
||||
public CreateAssetResponse createAsset(String url, String groupId, String assetType, String name) throws Exception {
|
||||
if (StringUtils.isBlank(groupId) || StringUtils.isBlank(groupId) || StringUtils.isBlank(assetType)) {
|
||||
throw new IllegalArgumentException("url、groupId、assetType 不能为空");
|
||||
}
|
||||
if (StringUtils.isBlank(groupId) || StringUtils.isBlank(assetType)) {
|
||||
throw new IllegalArgumentException("groupId、assetType 不能为空");
|
||||
}
|
||||
String publicUrl = tencentCosUtil.uploadMultipartFile(file, true);
|
||||
CreateAssetRequest request = new CreateAssetRequest();
|
||||
request.setGroupId(groupId);
|
||||
request.setUrl(publicUrl);
|
||||
request.setUrl(url);
|
||||
request.setName(name);
|
||||
request.setAssetType(assetType);
|
||||
request.setProjectName(getUserProject());
|
||||
|
|
|
|||
Loading…
Reference in New Issue