Modifying backend so it send the full entry of a file upload
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								backend/cdn/4f7f8ce8-98a9-45cd-835e-bf13d3a71d07.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								backend/cdn/4f7f8ce8-98a9-45cd-835e-bf13d3a71d07.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 292 KiB | 
							
								
								
									
										
											BIN
										
									
								
								backend/cdn/755d356e-899f-4486-932e-c2968099184b.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								backend/cdn/755d356e-899f-4486-932e-c2968099184b.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 81 KiB | 
							
								
								
									
										
											BIN
										
									
								
								backend/cdn/ea391659-ed46-4253-a4b7-d98914255998.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								backend/cdn/ea391659-ed46-4253-a4b7-d98914255998.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 81 KiB | 
							
								
								
									
										
											BIN
										
									
								
								backend/cdn/ee8994e4-74b0-426a-b3b0-a272b8815258.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								backend/cdn/ee8994e4-74b0-426a-b3b0-a272b8815258.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 81 KiB | 
| @ -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); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -27,7 +27,7 @@ public class StorageService { | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public String store(MultipartFile file, FileType fileType) { | ||||
|     public StorageFile store(MultipartFile file, FileType fileType) { | ||||
|  | ||||
|         if (file.getOriginalFilename().isEmpty()){return null;} | ||||
|  | ||||
| @ -49,9 +49,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 { | ||||
|  | ||||
							
								
								
									
										11
									
								
								frontend/src/rest/uploads.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								frontend/src/rest/uploads.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| import { restPostFile } from '@/rest/restConsumer.js' | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Upload a file to the server and return the url of this image | ||||
|  */ | ||||
| export async function uploadProfilePicture(file){ | ||||
| 	const formData = new FormData(); | ||||
| 	formData.append("file", file[0]); | ||||
| 	return restPostFile("/upload/ProfilePicture", formData) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user