|
|
|
@ -66,6 +66,7 @@ import io.swagger.annotations.ApiParam;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import util.DateUtil;
|
|
|
|
|
import util.IdWorker;
|
|
|
|
|
import util.ScaleFilter;
|
|
|
|
|
import util.StringTools;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@ -160,25 +161,38 @@ public class MyController extends BaseController {
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "3.上传个人头像", notes = "图片存入S3,桶为indie,目录为 user/avatar/")
|
|
|
|
|
@ApiOperation(value = "3.上传个人头像", notes = "图片存入S3,桶为indie,目录为 user/avatar/, 缩略图大小为200X200")
|
|
|
|
|
@PostMapping("/avatar")
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
public Result<String> uploadAvatar(@RequestHeader(value = "Authorization", required = true) String authorization,
|
|
|
|
|
@VerifyParam(required = true) MultipartFile file) throws IOException {
|
|
|
|
|
UserLoginDto userLoginDto = getUserLoginDto(authorization);
|
|
|
|
|
|
|
|
|
|
byte[] thumbnail = file.getBytes();//.createThumbnail(file.getInputStream(), Constants.LENGTH_512, Constants.LENGTH_512);
|
|
|
|
|
String avatarName = userLoginDto.getUserId() + "_" + idWorker.nextId()
|
|
|
|
|
byte[] avatar = file.getBytes();
|
|
|
|
|
String fileId=userLoginDto.getUserId() + "_" + idWorker.nextId();
|
|
|
|
|
String avatarName = fileId
|
|
|
|
|
+ StringTools.getFileSuffix(file.getOriginalFilename());
|
|
|
|
|
String filePath = USER_AVATAR_DIRECTORY + avatarName;
|
|
|
|
|
s3Service.uploadImage("indie", filePath, thumbnail);
|
|
|
|
|
String avatarFilePath = USER_AVATAR_DIRECTORY + avatarName;
|
|
|
|
|
s3Service.uploadImage("indie", avatarFilePath, avatar);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserInfo user = userInfoService.findById(userLoginDto.getUserId());
|
|
|
|
|
user.setAvatar(filePath);
|
|
|
|
|
user.setAvatar(avatarFilePath);
|
|
|
|
|
|
|
|
|
|
byte[] thumbnail = ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_200, Constants.LENGTH_200);
|
|
|
|
|
if(null!=thumbnail) {
|
|
|
|
|
String thumbnailName = fileId+"_thumbnail"
|
|
|
|
|
+ StringTools.getFileSuffix(file.getOriginalFilename());
|
|
|
|
|
String thumbnailFilePath = USER_AVATAR_DIRECTORY + thumbnailName;
|
|
|
|
|
s3Service.uploadImage("indie", thumbnailFilePath, thumbnail);
|
|
|
|
|
user.setThumbnail(thumbnailFilePath);
|
|
|
|
|
}else {
|
|
|
|
|
user.setThumbnail(avatarFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userInfoService.update(user);
|
|
|
|
|
rabbitTemplate.convertAndSend("userInfoCommentCache",userLoginDto.getUserId());
|
|
|
|
|
return Result.success(Constants.RESOURCE_PREFIX + filePath);
|
|
|
|
|
return Result.success(Constants.RESOURCE_PREFIX + avatarFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "4.查看他人信息", notes = "游客无法查看他人信息")
|
|
|
|
|