1.add thumbnail for userinfo

main
Gary 10 months ago
parent 3fa139fa10
commit ed8f8dec62

@ -59,6 +59,8 @@ public class Constants {
public static final Integer LENGTH_150 = 150;
public static final Integer LENGTH_200 = 200;
public static final Integer LENGTH_512 = 512;
public static final String IP_LOCATION_CHINA = "中国";

@ -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 = "游客无法查看他人信息")

@ -43,6 +43,10 @@ public class UserInfo implements Serializable {
*
*/
private String avatar;
/**
* 200X200
*/
private String thumbnail;
/**
*
*/

Loading…
Cancel
Save