2

I am writing a module in Microservices, where I have to write a rest end point to upload large files chunk by chunk and save each chunk in local tmp directory.. Will get input as chunk of video file.

I am using Java11, Jetty server, SpringBoot framework.

I have written a piece of code in controller as below:

@Named
@Singleton
@Path("/chunk")
public class FileUploadChunkController {

@POST
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_OCTET_STREAM})
    @Path("/uploadvideo")
    public Response uploadVideo(@FormDataParam("file")InputStream inputStream, @FormDataParam("file") FormDataContentDisposition contentDisposition , @Context final HttpServletRequest request) throws Exception {
        LOGGER.info("Inside method: uploadVideo");

}

When invoking the api with chunk file as data, it is not reaching to the controller POST method.

Could some one help me?

I have spent lot of time but did not get solution for it.

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
Priyanka Sinha
  • 61
  • 3
  • 10
  • This question doesn't show an effort to start this process. See ["how to ask"](https://stackoverflow.com/help/how-to-ask). Since it seems you are just getting into this topic, know that you will be implementing the [`PATCH`](https://tools.ietf.org/html/rfc5789) HTTP method (as opposed to the `PUT` or `POST` methods) to accomplish this. Start reading up on `PATCH` and spring / REST. – Joakim Erdfelt Jun 29 '20 at 20:55
  • Thanks Erdfelt. I have written a POST api using JaxRS, spring boot, opened 11. After running the application, when invoking the api, not able to reach the api. Could you check and let me know what wrong I am doing? Refer below code: – Priyanka Sinha Jun 29 '20 at 21:07
  • ``` @POST @Produces({MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_OCTET_STREAM}) @Path("/uploadvideo") public Response uploadVideo( @FormDataParam("file")InputStream inputStream,@FormDataParam("file") FormDataContentDisposition contentDisposition , @Context final HttpServletRequest request) throws Exception { { //other stuff here... return Response.ok().entity("upload api with request called.").build(); } ``` – Priyanka Sinha Jun 29 '20 at 21:09
  • I can see many examples in the internet using POST method. So I started with POST. – Priyanka Sinha Jun 29 '20 at 21:39
  • POST and PUT is for complete files, not partial or chunked. – Joakim Erdfelt Jun 30 '20 at 01:35
  • Edit your question to improve it, to add more details, etc. Don't do it in the comments section. – Joakim Erdfelt Jun 30 '20 at 01:35
  • Hi Erdfelt, I have edited the question. Can you have a look please. – Priyanka Sinha Jun 30 '20 at 04:22

0 Answers0