Код: Выделить всё
//correct method
// upload SampleData file
@PostMapping("/uploadSampleData")
@ResponseBody
public ResponseEntity uploadSamplesFile(@RequestParam("categoryType") CategoryType categoryType,
@RequestParam("documentType") DocumentFileType documentType,
@RequestParam("sampleDetailsId") String sampleDetailsId,
@RequestParam("file") MultipartFile file) {
try {
logger.info("Received a request to upload sample data file. on categoryType:{},documentType:{},sampleDetailsId,sampleDetailsId:{}", categoryType, documentType, sampleDetailsId);
// Check if file size exceeds 10MB
if (file.getSize() > 10 * 1024 * 1024) {
return ResponseEntity.badRequest().body("File size exceeds the allowed limit (10MB).");
}
String contentType = file.getContentType();
if (contentType != null &&
(contentType.startsWith("image") ||
contentType.startsWith("application/pdf") ||
contentType.startsWith("text") ||
contentType.startsWith("application/vnd.ms-excel") ||
contentType.startsWith("application/vnd.ms-powerpoint") ||
contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation") ||
contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))) { // Added for .xlsx files
ResourceMaster savedResource = resourceMasterService.saveFileSampleData(categoryType, documentType, file, sampleDetailsId);
// You can return any response, like the ID of the saved resource
return ResponseEntity.ok("File uploaded successfully. Resource ID: " + savedResource.getResourceId());
} else {
return ResponseEntity.badRequest().body("Unsupported file type. Please upload an Image, PDF, text, Excel, or PowerPoint file.");
}
} catch (CustomException e) {
// Handle file-related exceptions with a user-friendly message
logger.error("Error handling file: ", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There was a problem handling the file. Please try again.");
} catch (MethodArgumentTypeMismatchException e) {
// Handle MethodArgumentTypeMismatchException
String errorMessage = "Invalid value for parameter. Expected type: " + e.getRequiredType().getSimpleName();
logger.error("Method argument type mismatch: ", e);
return ResponseEntity.badRequest().body(errorMessage);
} catch (Exception e) {
// Handle other exceptions with a user-friendly message
logger.error("Unexpected error occurred: ", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An unexpected error occurred. Please try again later.");
}
}
Код: Выделить всё
2024-09-12T12:40:25.678+05:30 INFO 13022 --- [0.0-8081-exec-6] c.p.s.interceptor.MyInterceptor : logged in user is Admin : Amrata and group is Admin_all
Код: Выделить всё
2024-09-12 12:40:25 - logged in user is Admin : Amrata and group is Admin_all
Код: Выделить всё
2024-09-12T12:40:25.680+05:30 WARN 13022 --- [0.0-8081-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required part 'file' is not present.]
Код: Выделить всё
2024-09-12 12:40:25 - Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required part 'file' is not present.]
Код: Выделить всё
2024-09-12T12:40:25.681+05:30 DEBUG 13022 --- [0.0-8081-exec-6] o.s.security.web.FilterChainProxy : Securing POST /error?categoryType=SampleTDS&documentType=TDS&sampleDetailsId=PIO/24-25/00008/11/09
Код: Выделить всё
2024-09-12 12:40:25 - Securing POST /error?categoryType=SampleTDS&documentType=TDS&sampleDetailsId=PIO/24-25/00008/11/09
Код: Выделить всё
2024-09-12T12:40:25.682+05:30 DEBUG 13022 --- [0.0-8081-exec-6] o.s.security.web.FilterChainProxy : Secured POST /error?categoryType=SampleTDS&documentType=TDS&sampleDetailsId=PIO/24-25/00008/11/09
Код: Выделить всё
2024-09-12 12:40:25 - Secured POST /error?categoryType=SampleTDS&documentType=TDS&sampleDetailsId=PIO/24-25/00008/11/09
Код: Выделить всё
2024-09-12T12:40:25.683+05:30 INFO 13022 --- [0.0-8081-exec-6] c.p.s.interceptor.MyInterceptor : Inside preHandle method
Код: Выделить всё
2024-09-12 12:40:25 - Inside preHandle method
Может ли кто-нибудь понять, почему проблема возникает на сервере, в то время как на моем он работает нормально? локальный компьютер.
Заранее благодарим за любую помощь.
Подробнее здесь: https://stackoverflow.com/questions/789 ... ot-present