Merge pull request 'UploadAPI and profilePicture' (#102) from tonitch/front/apiUpload into master
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build and test backend / Build-backend (push) Successful in 2m13s
				
			
		
			
				
	
				deploy to production / deploy-backend (push) Successful in 2m21s
				
			
		
			
				
	
				Build and test FrontEnd / Build-frontend (push) Successful in 24s
				
			
		
			
				
	
				Build and test backend / Test-backend (push) Successful in 1m24s
				
			
		
			
				
	
				deploy to production / deploy-frontend (push) Successful in 26s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build and test backend / Build-backend (push) Successful in 2m13s
				
			deploy to production / deploy-backend (push) Successful in 2m21s
				
			Build and test FrontEnd / Build-frontend (push) Successful in 24s
				
			Build and test backend / Test-backend (push) Successful in 1m24s
				
			deploy to production / deploy-frontend (push) Successful in 26s
				
			Reviewed-on: #102 Reviewed-by: LeoMoulin <leomoulin125@gmail.com> Reviewed-by: Wal <karpinskiwal@gmail.com> Reviewed-by: Maxime <231026@umons.ac.be>
This commit is contained in:
		| @ -1,13 +1,12 @@ | ||||
| package ovh.herisson.Clyde.EndPoints; | ||||
|  | ||||
| import org.springframework.http.HttpHeaders; | ||||
| import org.springframework.http.HttpStatus; | ||||
| import org.springframework.http.ResponseEntity; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import org.springframework.web.multipart.MultipartFile; | ||||
| import ovh.herisson.Clyde.Services.StorageService; | ||||
| import org.springframework.core.io.Resource; | ||||
| import ovh.herisson.Clyde.Tables.FileType; | ||||
| import ovh.herisson.Clyde.Tables.StorageFile; | ||||
|  | ||||
| @RestController | ||||
| @CrossOrigin(originPatterns = "*", allowCredentials = "true") | ||||
| @ -21,12 +20,17 @@ public class StorageController { | ||||
|  | ||||
|  | ||||
|     @PostMapping("/upload/{fileType}") | ||||
|     public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file, @PathVariable FileType fileType) { | ||||
|     public ResponseEntity<StorageFile> handleFileUpload(@RequestParam("file") MultipartFile file, @PathVariable FileType fileType) { | ||||
|  | ||||
|         String path = storageServ.store(file,fileType); | ||||
| 		StorageFile fileEntry = null; | ||||
| 		try { | ||||
| 			fileEntry = storageServ.store(file,fileType); | ||||
| 			 | ||||
| 		} catch(Exception e){ | ||||
| 			e.printStackTrace(); | ||||
| 		} | ||||
|  | ||||
|         if (path == null) return new ResponseEntity<>("issue with the file storage", HttpStatus.BAD_REQUEST); | ||||
|  | ||||
|         return  new ResponseEntity<>(path, HttpStatus.OK); | ||||
|         return new ResponseEntity<>(fileEntry, HttpStatus.OK); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -35,7 +35,7 @@ public class StorageService { | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public String store(MultipartFile file, FileType fileType) { | ||||
|     public StorageFile store(MultipartFile file, FileType fileType) { | ||||
|  | ||||
|         if (file.getOriginalFilename().isEmpty()){return null;} | ||||
|  | ||||
| @ -57,9 +57,7 @@ public class StorageService { | ||||
|         String url = this.rootLocation.resolve(Paths.get(Objects.requireNonNull(stringUuid))) | ||||
|                 .normalize().toString(); | ||||
|  | ||||
|         fileRepo.save(new StorageFile(file.getName(),url, fileType)); | ||||
|  | ||||
|         return url; | ||||
|         return fileRepo.save(new StorageFile(file.getName(),url, fileType)); | ||||
|     } | ||||
|  | ||||
|     public void delete(StorageFile file) throws SecurityException { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user