cancel
Showing results for 
Search instead for 
Did you mean: 

Problem regarding File Upload

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Go through the following thread, its similar one

Regards

Abhijith YS

Answers (1)

Answers (1)

Former Member
0 Kudos

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

}

}