cancel
Showing results for 
Search instead for 
Did you mean: 

File Upload - check the file for existence

Former Member
0 Kudos

Hello, I am using the file upload UI element for uploading a local file and processing it. However, I do not know how to validate a manual input (if the user just types in something as the filename). Any processing after putting in a non-existing file (or nonsense) seems to hang forever. Could anyone propose a check for file existence in this case? Best regards, Werner

I paste the code which hangs if the file does not exist:

Code:

//create a ressource from the file data given

IWDResource myresource;

myresource = WDResourceFactory.createResource(wdContext.currentContextElement().getFileData().read(true),

wdContext.currentContextElement().getFileData().getResourceName(), WDWebResourceType.DOC, true);

Accepted Solutions (1)

Accepted Solutions (1)

raja_thangamani
Active Contributor
0 Kudos

Welcome to SDN..

Here is the sample code:

    String fileType = fileResource.getResourceType().getFileExtension().toUpperCase();

          if ("PDF".equals(fileType) || "DOC".equals(fileType) || "RTF".equals(fileType) || "TXT".equals(fileType))
          {
// Your Logic
          }

<i>*Reward each useful answer</i>

Raja T

Former Member
0 Kudos

Hello Raja, thanks a lot for the quick response.

My problem still remains, because in my installation the code you proposed is not reasched if someone specifies a non-existing file. I opened a OSS problem for that, it seems that this a bug.

Regards, Werner

Former Member
0 Kudos

Hi Werner,

Create a normal java program, using file handling u can check whether file is existing or not.Call that program before processing the file.

regards

Sumit

Former Member
0 Kudos

hi sumit

Can u provide little detail abt the solution u provided. I used file exists code but its not workin i have pasted the code I have used:

String hostName = TaskBinder.getCurrentTask().getProtocolAdapter().getServerName();

int port = TaskBinder.getCurrentTask().getProtocolAdapter().getServerPort();

String Protocol =TaskBinder.getCurrentTask().getProtocolAdapter().getProtocolScheme();

String logoName = "logo_" + wdContext.currentCompaniesElement().getBukrs()+".gif";

String companylogourl = Protocol + "://" + hostName + ":" + port + "/webdynpro/resources/local/eScCommonLogos/Components/com.ko.CommonLogos/" + logoName;

/Checking availablility of the image/

//String fileName=companylogourl;

File f=new File(companylogourl);

if (f.exists())

{

wdComponentAPI.getMessageManager().reportSuccess("file found");

wdContext.currentContextElement().setCxt_CompanyLogo(companylogourl);

}

else

{

wdComponentAPI.getMessageManager().reportSuccess("file Not found");

Please help if possible...

Thanks & Regards

Jaspreet Kaur

Former Member
0 Kudos

Hi jaspreet,

What's the problem u r getting exactly after using this code??

regards

Sumit

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Werner,

Try the folowing code:

IWDClientUser objUser = WDClientUser.getCurrentUser();

com.sap.security.api.IUser objSAPUser = objUser.getSAPUser();

IUser ep5User = WPUMFactory.getUserFactory().getEP5User(objSAPUser);

String strLocation = "<specify the path>";

RID objNewRid = RID.getRID(strLocation);

objResourceContext = new ResourceContext(ep5User);

objFactory = ResourceFactory.getInstance();

objResourceCheckRowwiseFolder = objFactory.getResource(objNewRid,objResourceContext);

if(objResourceCheckRowwiseFolder==null) //This checks whether such a folder exists or not.

{

}

else

{

}

Regards,

Shyam.

Former Member
0 Kudos

hi Shyam

I am facing a similar problem of checking whether a file exists or not...can u giv a breif explaination on the above code...as it may help me out as i am a fresher...and hv an urgent requirement..

Thanks & Regards

Jaspreet Kaur

Former Member
0 Kudos

Hi werner,

Do the following steps

In wdDoInit, create an element(instance) of the node. For this, declare the instance globally since it will be used in more than one methods (wdDoInit, onActionFileToSever).

It is declared as:

IPrivateFileUploadView.IFileElement element; (in begin others)

(FileUploadView is the name of the view)

In the onActionFileToServer method, specify the location where you want the file to be uploaded. On browsing, you get the file name in the value attribute assigned to the ‘filename’ property of FileUpload (File.FileName, in this case). Create a file by this name in the sever. The contents of the file is present in the value attribute ‘Upload’ in the form of binary data. This is written to the file created. This happens when you click the ‘FileToServer’ button. The code for this is given below.

N.B.:- Settings needed to be made in server for uploading a file.

In VisualAdmin&#61664;Services&#61664;Web Container, set the parameter MultipartBodyParameterName to com.sap.servlet.multipart.body

Thanks,

P.Manivannan.