|
@@ -202,22 +202,26 @@ public class ImageUrlToImageUrlServiceImpl implements FileMigrateService {
|
|
|
final String uploadUrlFormat = "{}{}?systemId={}&secret={}&key={}";
|
|
|
// 1.分批迁移文件
|
|
|
for (String destFileKey : destFileKeys) {
|
|
|
- if (StrUtil.isBlank(destFileKey)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- String downUrl = StrUtil.format(downloadUrl, fromImageServiceUrl, getSubUrl, fromSystemId,destFileKey);
|
|
|
- byte[] bytes = HttpUtil.downloadBytes(downUrl);
|
|
|
- String str = StrUtil.str(bytes, CharsetUtil.defaultCharset());
|
|
|
- if ("File not existed".equalsIgnoreCase(str) || "Image not existed".equalsIgnoreCase(str)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- String uploadUrl = StrUtil.format(uploadUrlFormat, toImageServiceUrl, uploadUriMap.get(getSubUrl), toSystemId, toSecret, destFileKey);
|
|
|
- HttpRequest httpRequest = HttpUtil.createPost(uploadUrl);
|
|
|
- httpRequest.body(bytes);
|
|
|
- httpRequest.header("Content-Type","application/json");
|
|
|
- HttpResponse response = httpRequest.execute();
|
|
|
- if(HttpStatus.HTTP_OK != response.getStatus()){
|
|
|
- log.debug("上传文件失败,返回的结果:"+JSONObject.toJSONString(response.body()));
|
|
|
+ try {
|
|
|
+ if (StrUtil.isBlank(destFileKey)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String downUrl = StrUtil.format(downloadUrl, fromImageServiceUrl, getSubUrl, fromSystemId,destFileKey);
|
|
|
+ byte[] bytes = HttpUtil.downloadBytes(downUrl);
|
|
|
+ String str = StrUtil.str(bytes, CharsetUtil.defaultCharset());
|
|
|
+ if ("File not existed".equalsIgnoreCase(str) || "Image not existed".equalsIgnoreCase(str)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String uploadUrl = StrUtil.format(uploadUrlFormat, toImageServiceUrl, uploadUriMap.get(getSubUrl), toSystemId, toSecret, destFileKey);
|
|
|
+ HttpRequest httpRequest = HttpUtil.createPost(uploadUrl);
|
|
|
+ httpRequest.body(bytes);
|
|
|
+ httpRequest.header("Content-Type","application/json");
|
|
|
+ HttpResponse response = httpRequest.execute();
|
|
|
+ if(HttpStatus.HTTP_OK != response.getStatus()){
|
|
|
+ log.debug("上传文件失败,返回的结果:"+JSONObject.toJSONString(response.body()));
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("迁移单个文件失败,错误的文件key:"+destFileKey+",错误结果:",e);
|
|
|
}
|
|
|
}
|
|
|
// 2.删除文件
|