on 06-12-2007 10:42 PM
Dear SDN Community,
I'm trying to upload a file to a server but the created file is empty.
I don't know how to bind the data file to the created file, I'm using this code:
Context atributtes
ResourceUp of type Resource bind to resource property of UploadFile
UploadStream of type Binary bind to data property of UploadFile
Code:
IPrivateP_PR_03.IContextElement element = wdContext.currentContextElement();
// if a file in the FileUpload field exists
if (element.getResourceUp() != null) {
IWDResource resource = element.getResourceUp();
// get the size of the uploaded file
element.setFileSize(this.getFileSize(resource));
// get the extension of the uploaded file
element.setFileExtension( resource.getResourceType().getFileExtension());
// set context attribute 'fileName' .
element.setFileName(resource.getResourceName());
String location = "/home_dev/sr1/dympro/";
String file = resource.getResourceName();
String filename = location+file;
File destinationFile = new File(filename);
try{
FileOutputStream out = new FileOutputStream(destinationFile);
if (wdContext.currentContextElement().getUploadStream() != null)
out.write(wdContext.currentContextElement().getUploadStream());
out.flush();
out.close();
}catch(Exception e){
messageMgr.reportException(e.getMessage(),false);
}
A prompt reply would be very much appreciated : )
Regards,
Hi
Upload the file using the File Upload component and bind a value attribute of type binary to the file upload UI.Create a button and assigna action>let the action for the button be submit.
Code:
public void onActionSubmit(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionSubmit(ServerEvent)
IWDAttributeInfo attInfo =wdContext.getNodeInfo().getAttribute("<value attribute name>");
IWDModifiableBinaryType binaryType;
binaryType =(IWDModifiableBinaryType) attInfo.getModifiableSimpleType();
fileuploaded = binaryType.getFileName();
byte b[] = wdContext.currentContextElement().get<value attribute name>();
File filename =new File("
sharelocation"+fileuploaded);
try {
FileOutputStream out = new FileOutputStream(filename);
out.write(b);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
//@@end
}
hope this helps
Thanks and Regards,
Arun
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Arun,
I have the same problem with your code,
upload = binaryType.getFileName() // is empty
byte b[] = wdContext.currentContextElement().getUpload(); // is empty too
A have defined a atributte of type binary (Upload) and I have bind it to the Upload File data property
you know if i can fill b[] from Upload File resource property?
Thanks and Regards,
Juan Luis
Hi, I'm uploading documents of type .txt .doc .xls .pdf ....
Naga this line
byte[]=wdContext.currentContextElement().getResource().read(true);
give me an error because wdContext.currentContextElement().getResource().read(true); returns a Inputstream and I need a type byte.
I have tried this:
byte b[]=null;
InputStream inputS = wdContext.currentContextElement().getResource().read(true);
inputS.read(b);
File filename =new File("/home_dev/sr1/dympro/" + file);
FileOutputStream out = new FileOutputStream(filename);
out.write(b);
out.flush();
out.close();
But this code give me an Null pointer exception at out.write(b);
Thanks and Regards,
Juan Luis
Hai,
FileInputStream inputS = wdContext.currentContextElement().getResource().read(true);
FileChannel srcChannel = fis.getChannel();
// Create channel on the destination
FileChannel dstChannel = new FileOutputStream(("/home_dev/sr1/dympro/" + file).getChannel();
// Copy file contents from source to destination
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
// Close the channels
srcChannel.close();
dstChannel.close();
Regards,
Naga
Hello Luis,
Check out this link... this may help you..
http://www.sapdevelopment.co.uk/file/file_updown.htm
Regards,
Arun
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Check this url
Transport, Upload and Monitoring
http://help.sap.com/saphelp_nw04/helpdata/en/0d/13df3fa510031ee10000000a155106/frameset.htm
Regards
Chandran
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Have a look into this tutorial... it will clear all your doubts regarding uploading and downloading file using webdyunpro for JAVA....
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/202a850a-58e0-2910-eeb3-bfc3e081257f">Uploading and Downloading Files in Web Dynpro Java</a>
Please reward points if it helps..
Thanks and Regards
Avijit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
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.