1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public String buttonUpload_action() {
// Process the upload button click action.
UploadedFile uploadedFile = fileUpload.getUploadedFile();
String uploadedFileName = uploadedFile.getOriginalName();
// Some browsers return complete path name, some don't
// Make sure we only have the file name
// First, try forward slash
int index = uploadedFileName.lastIndexOf('/');
String justFileName;
if ( index >= 0) {
justFileName = uploadedFileName.substring( index + 1 );[/INDENT]
} else {
// Try backslash
index = uploadedFileName.lastIndexOf('\\');
if (index >= 0) {
[INDENT]justFileName = uploadedFileName.substring( index + 1 );
} else {
// No forward or back slashes
justFileName = uploadedFileName;
}
}
Long uploadedFileSize = new Long(uploadedFile.getSize());
String uploadedFileType = uploadedFile.getContentType();
if ( uploadedFileType.equals("image/jpeg")
|| uploadedFileType.equals("image/gif")
|| uploadedFileType.equals("application/vnd.ms-excel")) {
try {
String toSave = getSessionBean1().fabriqueNomFichierUpload(justFileName); //fabriqueNomFichierUpload pour générer un nom de fichier
File file = new File(this.realImageFilePath + File.separatorChar + toSave); //realImageFilePath est le répertoire de mon serveur où j'enregistre
uploadedFile.write(file);
info("You succefully uploaded the file: " + justFileName);
} catch (Exception ex) {
error("Cannot upload file: " + justFileName);
}
} else {
error("You must upload a XLS(excel below 2003), JPEG,or GIF file.");
new File(this.realImageFilePath).delete();
}
return null;
} |
Partager