80.2 Get user profile image - by userId (#9)
This commit is contained in:
@ -117,6 +117,13 @@ public class UserResource {
|
||||
return profileImage;
|
||||
}
|
||||
|
||||
@GetMapping(path = "image/profile/{userId}/{filename}", produces = MediaType.IMAGE_JPEG_VALUE)
|
||||
public byte[] getProfileImageByUserId(@PathVariable String userId, @PathVariable String filename) throws IOException {
|
||||
byte[] profileImage = userService.getImageByUserId(userId, filename);
|
||||
log.debug("File size: {}", profileImage.length);
|
||||
return profileImage;
|
||||
}
|
||||
|
||||
private void authenticate(String username, String password) {
|
||||
Authentication auth = new UsernamePasswordAuthenticationToken(username, password);
|
||||
authenticationManager.authenticate(auth);
|
||||
|
||||
@ -30,4 +30,6 @@ public interface UserService extends UserDetailsService {
|
||||
|
||||
byte[] getProfileImage(String username) throws IOException;
|
||||
|
||||
byte[] getImageByUserId(String userId, String filename) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@ -220,9 +220,14 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public byte[] getProfileImage(String username) throws IOException {
|
||||
User user = findByUsername(username);
|
||||
Path userFolder = Paths
|
||||
.get(USER_FOLDER, user.getUserId(), USER_IMAGE_FILENAME);
|
||||
return Files.readAllBytes(userFolder);
|
||||
return getImageByUserId(user.getUserId(), USER_IMAGE_FILENAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getImageByUserId(String userId, String filename) throws IOException {
|
||||
Path userProfileImagePath = Paths
|
||||
.get(USER_FOLDER, userId, filename);
|
||||
return Files.readAllBytes(userProfileImagePath);
|
||||
}
|
||||
|
||||
private void validateNewUsernameAndEmail(String username, String email) {
|
||||
|
||||
Reference in New Issue
Block a user