1

I'm trying to make an Image host thath could be identified by an url. For GET Method I'he done like this:

 @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String filename = request.getParameter("id");
    String path = request.getServletContext().getRealPath("/uploaded");
    File folder=new File(path);
    File file = new File(folder,filename);
    if (!file.exists()) 
        throw new ServletException("file not found");

    response.setContentLength((int)file.length());
    OutputStream out = response.getOutputStream();
    FileInputStream in = new FileInputStream(file);
    byte[] buffer = new byte[1024];
    int length;
    while ((length = in.read(buffer)) > 0) {
        out.write(buffer, 0, length);
    }
    in.close();
    out.flush();
}

If I try it in my developement environment (Netbeans+Glassifh) everithing go smooth but when i deploy it in Amazon Web Services response is like this: �bc"IdIX�P�F��IJ/)�

Can you help me? Thank you!

2
  • Perhaps it has to do with the character encoding. Your local environment might use a different variant than the AWS default and since you haven't specified anything it might get messed up. But that's just a guess. Commented Jan 1, 2018 at 14:46
  • 2
    Not to do with the error but set the ContentType of the response. Commented Jan 1, 2018 at 14:57

1 Answer 1

1

Try setting an appropriate Content-Type of the response

e.g. for JPEG images:

response.setContentType("image/jpeg");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.