small fixes
This commit is contained in:
1 parent
4c3f5ee9fd
commit
1b8c11798a
3 files changed
+5
-6
No files matched your search
@@ -65,16 +65,15 @@ public class ImageController {
|
||||
public ResponseEntity<?> addImage(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {
|
||||
|
||||
String contentType = file.getContentType();
|
||||
if (!contentType.equals(MediaType.IMAGE_JPEG.toString())) {
|
||||
if (contentType != null && !contentType.equals(MediaType.IMAGE_JPEG.toString())) {
|
||||
return new ResponseEntity<>("Only JPEG file format supported", HttpStatus.UNSUPPORTED_MEDIA_TYPE);
|
||||
}
|
||||
|
||||
try {
|
||||
imageDao.create(new Image(file.getOriginalFilename(), file.getBytes()));
|
||||
} catch (IOException e) {
|
||||
return new ResponseEntity<>("Failure to read file", HttpStatus.NO_CONTENT);
|
||||
}
|
||||
return new ResponseEntity<>("Image uploaded", HttpStatus.OK);
|
||||
return new ResponseEntity<>("Image uploaded", HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/images", produces = "application/json")
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ImageDao implements Dao<Image> {
|
||||
|
||||
public ImageDao() {
|
||||
try {
|
||||
final File folder = new File("backend/src/main/resources/images");
|
||||
final File folder = new File("images");
|
||||
getAllImages(folder);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -75,11 +75,11 @@ public class ImageControllerTests {
|
||||
@Test
|
||||
@Order(7)
|
||||
public void createImageShouldReturnSuccess() throws Exception {
|
||||
final ClassPathResource imgFile = new ClassPathResource("test.jpg");
|
||||
final ClassPathResource imgFile = new ClassPathResource("images/test.jpg");
|
||||
MockMultipartFile multipartFile = new MockMultipartFile("file", "test.jpg", "image/jpeg",
|
||||
imgFile.getInputStream());
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.multipart("/images").file(multipartFile)).andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
.andExpect(status().isCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user