0

I am using Cloudinary to handle file uploads in my Java Spring application. I have a @PutMapping endpoint that receives a video file using multipart/form-data. However, when I attempt to upload the video file, I receive the following error: the request was rejected because its size (27838844) exceeds the configured maximum (10485760)

It seems that Cloudinary is treating the file as an image and applying the lower file size limit instead of the expected limit for videos. How can I specify to Cloudinary that the uploaded file is a video, so that the correct file size limit is applied?

@PutMapping(value = "/update/{id}", consumes = "multipart/form-data")
  public ResponseEntity<Map<String, Object>> UpdateCourse(@RequestParam("file"MultipartFile file, HttpServletRequest request) throws IOException {
Map<String, Object> response = new HashMap<>();
response.put("filename", file.getBytes());

try {
    Map<String, Object> name = cloudinary.uploader().upload(file.getInputStream(), ObjectUtils.asMap("resource_type", "video"));

    response.put("message", "File uploaded successfully");
    response.put("url", name.get("secure_url"));
} catch (Exception e) {
    LOG.info(e.getMessage());
}

return ResponseEntity.ok(response);

}

I have verified that the video file size exceeds the default file size limit for images. I have also checked my Cloudinary account settings and confirmed that the maximum video file size limit is indeed set to a higher value than the error suggests. I have tried specifying "resource_type" as "video" in the options passed to cloudinary.uploader().upload(), but the issue persists. I appreciate any insights or suggestions on how to resolve this issue and correctly specify the file type as a video during the upload process. Thank you!

  • Are you sure that error come from cloudinary not from servlet? May be you limit servlet container of upload file size? Check spring boot config parameter to increase multipart size of underneath servlet container. Also you code is tricks the error it catches both error types: from container and from cloudinary. If you able to catch exception debug mode pay attention what type of error is it. – simar Jun 08 '23 at 12:20
  • Replace LOG.info(e.getMessage()); with LOG.error("", e); this will also will log type of error, not just generic string message which may be common for both io errors. – simar Jun 08 '23 at 12:21
  • Or may be you need to replace "upload" with "uploadLarge" – simar Jun 08 '23 at 12:26
  • Your code doesn't even execute I would say. The error is thrown by the default file upload handling from Spring Boot which has this limit. Set to a larger limit or disable file upload as a whole and use a streaming approach (which will use less resources). – M. Deinum Jun 08 '23 at 12:56
  • If you could also please retry an upload request and log/print the value of the exact error message returned from Cloudinary API - that would help. – Aleksandar Jun 08 '23 at 13:13
  • Thank you guys for your suggestion. In deed the problem was spring. I added the following to application properties spring.servlet.multipart.max-file-size=100MB spring.servlet.multipart.max-request-size=100MB. I would like to know more about the streaming approach. Could you tell me more M.Deinum ? – Šimon Kováč Jun 08 '23 at 18:02

0 Answers0