I have 2 microservices. The first service(video converter) and the second service(integration Spring with Amazon S3 to store video and image on the Amazon S3).
The first service produces files by schedule and after converts File
to MultipartFile
uploads it to the second service and after to Amazon S3.
But I stack on the issue with Feigh uploading the video.
When I debug, I saw that the file in @RequestPart
in the second service is null
. But converting was done successfully.
I try adding encoding as in that post File upload spring cloud feign client, but that does not help.
Code sample first microservice: Upload methods:
@Override
public Response<String> uploadFile(final Object object, final MultipartFile multipartFile) {
final Map<String, Object> s3Url = videoServiceFeign.uploadFile(multipartFile,
object.getId().toString(), object.getIdIds().toString(), object.getName());
object.setS3Url(s3Url.get("object").toString());
return generateSuccessResponse();
}
@Override
public Response<String> uploadFile(final Stream stream, final File file) throws IOException {
final InputStream inputStream = Files.newInputStream(file.toPath());
final MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(),
ContentType.MULTIPART_FORM_DATA.toString(), IOUtils.toByteArray(inputStream));
return this.uploadFile(stream, multipartFile);
}
Feign client:
@FeignClient(name = "video-service", url = "${video-service.ribbon.listOfServers}")
public interface VideoServiceFeign {
@PostMapping(path = "/api/v1/video/upload", consumes = {"multipart/form-data"})
Map<String, Object> uploadFile(@RequestPart("file") MultipartFile multipartFile,
@RequestParam("id") String id,
@RequestParam("ids") String ids,
@RequestParam("name") String name);
}
Upload endpoint in the second service:
@ApiOperation("Upload new video file")
@ApiResponses({
@ApiResponse(code = 200, message = "File uploaded successfully"),
@ApiResponse(code = 403, message = "Access Denied"),
@ApiResponse(code = 500, message = "Internal server error"),
@ApiResponse(code = 503, message = "Gateway timeout")
})
@ResponseStatus(HttpStatus.OK)
@PostMapping(value = "/upload", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public @ResponseBody
Map<String, Object> uploadFile(@RequestPart("file") final MultipartFile file,
@RequestParam("id") final String id,
@RequestParam("ids") final String ids,
@RequestParam("name") final String name
) throws IOException {
return uploadService.uploadFile(id, ids, name, file);
}
What am I missing?