cancel
Showing results for 
Search instead for 
Did you mean: 

I need some information about File Download & File Upload

Former Member
0 Kudos

Hi All,

Can any one help me on this, I need some information about File Download & File Upload.

I read tutorial abt file upload and download but some of methods in tutorial are deprecated so i need clear information abt File upload and Download, if possible Code examples.

Thanks

Ragards

Ravi Golla

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Ravi,

Create a context attribute and set calculated as true then u will get a getter method,In that u write code like this

IWDInputStream stream = null;

try {

stream = WDResourceFactory.createInputStream(new FileInputStream(new File(<give the location of a file u want to download>));

}

catch (Exception e)

{

e.printStackTrace();

}

return stream;

for open file u set "resource"as Resource type context attribute.

former_member187702
Active Participant
0 Kudos

Hi Ravi

Check out thses links for examples:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a...

/docs/DOC-8661#22 [original link is broken]

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/202a850a-58e0-2910-eeb3-bfc3e081...

Otherwise you can simply follow this code for file download

Use the code like this.

1) Create the button and bind the action for it.

2)then write this code in the action.

3) do not write any thing in the init method.

try {

final byte[] content = this.getByteArrayFromResourcePath("C:
xyz.properties");

final IWDCachedWebResource resource = WDWebResource.getWebResource(content, WDWebResourceType.UNKNOWN);

try {

final IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(resource.getAbsoluteURL(), "WD_Filedownload", false);

window.open();

}

catch(Exception e)

{

wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);

}

5) writr the method getByteArrayFromResourcePath

//@@begin others

private byte[] getByteArrayFromResourcePath(String resourcePath)

throws FileNotFoundException, IOException {

FileInputStream in = new FileInputStream(new File(resourcePath));

ByteArrayOutputStream out = new ByteArrayOutputStream();

int len;

byte[] part = new byte[10 * 1024];

while ((len = in.read(part)) != -1) {

out.write(part, 0, len);

}

in.close();

return out.toByteArray();

}

//end

Similarly for file upload

Similarly for upload in to server path also do the same

IWDAttributeInfo attInfo =

wdContext.getNodeInfo().getAttribute("upload");

binaryType =

(IWDModifiableBinaryType) attInfo.getModifiableSimpleType();

uploadedName = binaryType.getFileName();

File filename =new File("

<server name>
<folder name>
"+uploadedName ); );

try {

FileOutputStream out = new FileOutputStream(filename);

out.write(b);

out.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Former Member
0 Kudos

Hi Ravi,

For uploading use this code

try{

String Upload=wdContext.currentContextElement().getResource().getResourceName();

FileOutputStream fout=new FileOutputStream(new File(upload));

}

catch(Exception e)

{

e.getStackTrace();

}

Former Member
0 Kudos

Ravi,

See <a href="/people/bertram.ganz/blog/2007/05/25/new-web-dynpro-java-tutorials--uploading-and-downloading-files-in-sap-netweaver-70 and Downloading Files in SAP NW 7.0</a> by <a href="https://forums.sdn.sap.com/profile.jspa?userID=585">Bertram Ganz</a>

Valery Silaev

SaM Solutions

http://www.sam-solutions.net