Skip to Content
avatar image
Former Member

file upload in webdynpro java

Hi, I have a reqirement where I have to upload the file ino server, and later user can down load the same from server.

i have seen file upload and down load example in SDN /docs/DOC-8061#15

but here they are just displaying the name and other details of the file that is trying upload but they are not really uploading the file in to the server. can any one guide me how to upload the file and where does the uploaded file resides in the server once it is succeefully uploded.

Regards,

Venki.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 05, 2008 at 07:18 AM

    Hi Venki,

    1.) Take One Context Attribute named as "D1" of Type "binary".

    2.) Take one FileUpload UI Element in the Layout Tab.

    3.) Bind FileUpload UI Element's data Property to the taken Context Attribute. Here it is "D1".

    4.) Take one Button UI Element in the Layout Tab named "Upload" and in the Action of that Button write the following Code.

    5.) The following code Generates one Folder in the Server & inside that Folder given file is Uploaded.

    File ff=new File("FolderXYZ"); // Creates One Folder with the given Name ( Here Folder name is "FolderXYZ")

    ff.mkdir();

    try

    {

    byte b[]=null;

    IWDAttributeInfo objAttinfo=null;

    IWDModifiableBinaryType binType=null;

    File f=null;

    FileOutputStream fos=null;

    if(wdContext.currentContextElement().getD1()!=null)

    {

    b=wdContext.currentContextElement().getD1();

    objAttinfo=wdContext.getNodeInfo().getAttribute(IPrivateAttachView.IContextElement.D1);

    binType=(IWDModifiableBinaryType)objAttinfo.getModifiableSimpleType();

    f=new File(ff.getName()"
    "
    binType.getFileName());

    fos=new FileOutputStream(f);

    fos.write(b);

    fos.flush();

    fos.close();

    }

    objMessageManager.reportSuccess("File uploaded to server");

    } catch (Exception e)

    {

    objMessageManager.reportException("Unable to upload file to server, error is:"+e,false);

    return;

    }

    The Uploaded file is stored in the folder & that folder is stored in the Server's following Path.

    <Your Server>\c$\usr\sap\J2E\JC00\j2ee\cluster\server0

    You can access your Uploaded file from the following Path

    <Your Server>\c$\usr\sap\J2E\JC00\j2ee\cluster\server0\FolderXYZ

    With Regards,

    Roop Kumar.

    Edited by: Roop kumar Annavarapu on Sep 5, 2008 12:49 PM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Roop,

      I have created the attribute and action as you said; still I am not able to upload the file.

      I have debugged the application and found that the application not able to go inside if() loop.

      if(wdContext.currentContextElement().getD1()!=null)
      {
      ----
      }

      Thanks and Regards,

      Pravin

  • avatar image
    Former Member
    Sep 05, 2008 at 06:35 AM

    Hi

    refer to the following application

    Uploading and Downloading Files in Web Dynpro Tables

    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0e10426-77ca-2910-7eb5-d7d8982cb83f

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 05, 2008 at 10:48 AM

    Hi,

    create a context attribute "Download" of type com.sap.ide.webdynpro.uielementdefinitions.Resource.

    Create a ui element File download , in properties bind the attribute "Download" to property resource.

    write this code in wdDoinit( ) method

    // this code is to get any one file from server root location. based on this example you can do whatever you want
    try {
    File Dir=new File(".");
    File list[]=Dir.listFiles();
    if(!list<i>.isDirectory){
    
    		String resourcePath ="";
    		StringTokenizer st=new StringTokenizer(SelectedElement.getText(),".");
    		st.nextToken();	String h=st.nextToken();
    		WDWebResourceType wdType=WDWebResourceType.getWebResourceTypeForFileExtension(h);
    		if(wdType==null)
    		wdType=WDWebResourceType.UNKNOWN;
    		IWDResource resource =WDResourceFactory.createResource(new FileInputStream(new File(resourcePath)),SelectedElement.getText(),wdType,true);
    		wdContext.currentContextElement().setDownload(resource);
    }	
    		} catch (FileNotFoundException e) {
    			   wdComponentAPI.getMessageManager().reportException(e+e.getLocalizedMessage(),true);
    		 }catch (Exception e) {
    		  wdComponentAPI.getMessageManager().reportException(e+e.getLocalizedMessage(),true);
    	}
    
    

    Regards,

    Naga

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 07, 2008 at 03:35 PM

    Try this,

    This will be helpful

    /docs/DOC-8661#section5

    Regards

    -sandip

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 08, 2008 at 06:40 AM
    Add comment
    10|10000 characters needed characters exceeded