on 09-20-2007 9:34 AM
Hi,
I have successfully completed the TutWD_FileUpDownload_NW04s_Init. But I am unable to understand where the file is uploaded.Please help me. Its urgent.
Regards
Nutan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If the file is successfully uploaded, it's content is stored in the Web Dynpro context. If you want to save it to disk, you could add the following code to the onActionUploadFile method.
//IWDModifiableBinaryType binaryType =
//byte[] file =
writeByteArrayToFile(new File("/tmp/" + binaryType.getFileName()), file);
The next code is copied from Commons IO's FileUtils
public static FileOutputStream openOutputStream(File file) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file + "' exists but is a directory");
}
if (file.canWrite() == false) {
throw new IOException("File '" + file + "' cannot be written to");
}
} else {
File parent = file.getParentFile();
if (parent != null && parent.exists() == false) {
if (parent.mkdirs() == false) {
throw new IOException("File '" + file + "' could not be created");
}
}
}
return new FileOutputStream(file);
}
public static void writeByteArrayToFile(File file, byte[] data) throws IOException {
OutputStream out = null;
try {
out = openOutputStream(file);
out.write(data);
} finally {
closeQuietly(out);
}
}
public static void closeQuietly(OutputStream output) {
try {
if (output != null) {
output.close();
}
} catch (IOException ioe) {
// ignore
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.