Hi guys and girls !
I need to make a button on a HTML page in order to allow user to save (download) a given image to it's disk. The problem is that the image is located on a server that needs autentication. I managed to do it using the following method :
The prob is that the response url looks like " so when the browser opens the "save as" dialog, the name given to the saved file is "FileItem.extractImage.wbx". Does anybody got an idea on :
[ul][li]How to retrieve mime type (and eventually the name) of the image ?[/li]
[li]Force the name (or just extension) of file name to save (by setting the response header for example) ?[/li]
[/ul]
Thanks for any clue...
Water is not bad as long as it remains outside human body ;-)
I need to make a button on a HTML page in order to allow user to save (download) a given image to it's disk. The problem is that the image is located on a server that needs autentication. I managed to do it using the following method :
Code:
public void extractImage() {
String urlParam = (String) params.get("URL"); // retrive img url
try {
urlParam = oper.getContextualUrl(urlParam); // adding authentication
URL url = new URL(urlParam);
InputStream is = url.openStream();
ByteArrayOutputStream buff = new ByteArrayOutputStream();
int b= is.read();
while (b!=-1) {
buff.write(b);
b= is.read();
}
String contentType = "application/download";
response.setContentType(contentType);
OutputStream os = null;
try {
os = response.getOutputStream();
os.write(buff.toByteArray());
} catch (IOException e) {
logger.error(e);
displayException("Unable to write file on ouput",e);
} finally {
if(os != null) try{os.close();}catch(Exception silentErr){};
}
} catch (Exception e) {
logger.error(e);
displayException(e);
}
}
The prob is that the response url looks like " so when the browser opens the "save as" dialog, the name given to the saved file is "FileItem.extractImage.wbx". Does anybody got an idea on :
[ul][li]How to retrieve mime type (and eventually the name) of the image ?[/li]
[li]Force the name (or just extension) of file name to save (by setting the response header for example) ?[/li]
[/ul]
Thanks for any clue...
Water is not bad as long as it remains outside human body ;-)