0

So I'm trying to download a file that I upload before, using a rest get method but sometimes I get file not found error and other times it just works. I don't know where the problem is.

I also tried the code that is in this thread file downloading in restful web services and changed it a little but the problem with this code is that I don't see the contents of the files so my solution is a little better I think.

@GET
  @Path("/{fileName}")
  @Produces(MediaType.APPLICATION_OCTET_STREAM)
  public Response downloadFile(@PathParam("fileName") String fileName) throws IOException
  {
    File ivyFile = new File(fileName);
    byte[] data = ivyFile.readBinary().toByteArray();
    StreamingOutput fileStream = new StreamingOutput()
      {
        @Override
        public void write(java.io.OutputStream output)
        {
          try
          {
            output.write(data);
            output.flush();
          }
          catch (IOException e)
          {
            throw new WebApplicationException("Could not Find the file: '" + fileName + "'", e);
          }
        }
      };
    return Response.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM)
            .header("content-disposition", "attachment; filename = " + fileName).build();
  }

I expect to download the file with the content and be able to see it.

EDIT: Also I get response 200 when this error occures. And this error as well:

MalformedChunkCodingException: CRLF expected at end of chunk
    FacesException: org.apache.http.MalformedChunkCodingException: CRLF expected at end of chunk
    Error during rendering of html dialog 'com.axonivy.connectivity.rest.FileUpload'
jackra1n
  • 63
  • 3
  • 7

1 Answers1

0

I found the solution. The problem was with my IDE that was causing a timeout for the download.

jackra1n
  • 63
  • 3
  • 7