cancel
Showing results for 
Search instead for 
Did you mean: 

File upload

Former Member
0 Kudos

Hi,

I am using the File upload UI element to upload a file. Is it possible to get the File path information from the UI element?? If so, how?

Regards

Praveen

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos
Former Member
0 Kudos

Hi Praveen

I guess this weblog might help you

/people/rekha.malavathu2/blog/2006/12/12/handling-fileupload-and-filedownload-in-netweaver-developer-studionwds-2004s

Regards

Rahul

Former Member
0 Kudos

Hi Praveen,

When you upload file through fileupoad UI element all the information and data of the file get stored in your context .

Here are the steps:

1.Create a node <NameOfNode> with cardinality 1:n and an attribute <NameOfAttribute> of type "com.sap.ide.webdynpro.uielementdefinitions.Resource"

2.IPrivate<View_Name>.I<NameOfNode>Element element = wdContext.current<NameOfNode>Element();

Regards,

Rajeev

Former Member
0 Kudos

Hi,

The method file.getPath() is returning the file name only. when I used file.getAbsolutePath() it is giving me the path in the J2EE server. But I want the local file system path.

Any idea how to get the file system path?

Regards

Praveen

Former Member
0 Kudos

Praveen,

Simple answer: this is not possible. It is even can be considered as security vulnerability if server knows path of file on client machine. IE (not all versions) sends this path, Mozilla/Firefox does not.

Btw, why you need path of file on client machine? Probably you are solving wrong problem

VS

Former Member
0 Kudos

Hi,

I require the file system path because I am calling a BAPI to checkin the document into SAP R/3. The BAPI expects a file system path as input and not a server path.

I assume there is no security issue here. If the application is alowing you to browse the client machine file system to upload a particular file then what's wrong in getting the file system path of that file?

Any workaround to get the path?

Regards

Praveen

Sigiswald
Contributor
0 Kudos

Not quite, the application isn't allowing anything. All the application says is it needs a file and the browser (on the client!) has a widget that allows browsing the file system and select a file. When submitting the form, the browser includes the actual content of the file in the request together with the file name. But the browser doesn't tell the server where the file comes from (or at least it shouldn't). There's absolutely no reason the server side application should know the location of the file, and it shouldn't care either. All it needs is the file content and some metadata like the filename and the MIME type.

If your BAPI requires a system path, it likely needs this to know where the file should be stored "in R/3". That would be a path on the machine where R/3 is running, or more likely some path on your document server.

Kind regards,

Sigiswald

Former Member
0 Kudos

Hi,

Could you please give me solution ??

We are to do the same.

Thanks,

Former Member
0 Kudos

Hi,

I am not getting the "IUploadFileElement" in the line

IPrivate<View_Name>.IUploadFileElement element = wdContext.currentUploadFileElement();

It lists IContextNode and IContextElement only and there is no IUploadFileElement.

Any idea?

- Praveen

pravesh_verma
Active Contributor
0 Kudos

Hi Praveen,

Yes it will not come. Actully I have created a Node in the context of the view, named: <b>"UploadFile"</b>, and in that I have created a new attribute named <b>"FileName"</b>, of type: <b>com.sap.ide.webdynpro.uielementdefinitions.Resource</b>

Then only you will get the "IUploadFileElement" in the line.

I hope this will solve your problem.

Regards

Pravesh

PS: Please consider rewarding points if helpful.

Former Member
0 Kudos

Hi,

That solved the error in that line. Now I am getting a nullpointer exception because "element" is coming as null.

IPrivateFileBrowse.IUploadFileElement element = wdContext.currentUploadFileElement();

Here is the code:

public void onActioncomplete(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

String strPath = new String();

IPrivateFileBrowse.IUploadFileElement element = wdContext.currentUploadFileElement();

if (element != null) {

File file = new File(element.getFileName().getResourceName());

strPath = file.getPath();

}else {

strPath = "No path found: ";

}

wdThis.wdGetFileBroInterfaceController().complete(strPath);

}

- Praveen

pravesh_verma
Active Contributor
0 Kudos

Hi Praveen,

It should not come as null pointer.

Have you created the Upload UI element and mapped the Element in the context to the "resource" property of the Upload UI. If not please do that.

I think this should solve the problem.

Regards

Pravesh

pravesh_verma
Active Contributor
0 Kudos

Hi Praveen,

For the FileUpload UI you can get the file path information by this code.

IPrivate<View_Name>.IUploadFileElement element = wdContext.currentUploadFileElement();

  	InputStream text=null;
	int temp=0;  	
	
    try {
    	
		//	If a file in the FileUpload field exists
    	
//    	-----   Code to upload to the server ----- 
    	File file = new File(element.getFileName().getResourceName());
		FileOutputStream out = new FileOutputStream(file);
		//    	-----   End of code -----		
    	if (element.getFileName() != null) {

    		text = element.getFileName().read(false);
    		
//        	-----   Code to upload to the server -----  		
			 while((temp=text.read())!=-1)
			 {
			 out.write(temp);
			 }
//        	-----   End of code -----
    		
		}

    	out.flush();
    	out.close();
   
<b>//      ------ To get the File Path -----------
    	String filePath = file.getPath();</b>} 
    
    catch (IOException e2) 
	{
    	e2.printStackTrace();
	}

I hope this helps you.. For any further details kindly revert back.

Regards

Pravesh