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!