cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get the filename from file upload UI element

0 Kudos

Hi,

I added a FileUpload UI element.

I created an attribute of type resource , assigned to the resource property of the file upload element.

I created an action button called upload and added the following code.

try {

IWDResource resource = wdContext.currentContextElement().getFileupload();

} catch (Exception e) {

e.printStackTrace();

}

when I debug to see the value of resource it is null.

Please let me know where I am going wrong.

Regards,

Narayani

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Narayani,

Please go to the followinf code. This code take the Resource object and bind it to the respective resouce.

Hope this will help you.

try{

String path = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),"LocalConveyance.pdf"); // gets the path of local object.

try{

InputStream stream = new FileInputStream(path);

IWDResource LocalConveyanceResource = WDResourceFactory.createResource(stream, "LocalConveyance.pdf", WDWebResourceType.PDF, true);

wdContext.currentContextElement().setLocalConveyanceTarget(LocalConveyanceResource); //LocalConveyanceTarget is the context with type RESOURCE.

wdContext.currentContextElement().getLocalConveyanceTarget();

}

catch(IOException b)

{

b.getMessage();

}

}

catch(WDAliasResolvingException e)

{

e.getMessage();

}

Regards,

Roshan

0 Kudos

Hi,

Thanks for the help but It doesnot solve my problem.

I am getting the following exception:

java.net.URISyntaxException: Illegal character in query at index.

Regards,

Narayani

Answers (5)

Answers (5)

0 Kudos

closed as an OSS message was raised

Former Member
0 Kudos

Hi

Which version of NWDS are you using ?

try{

IWDResource resource = wdContext.currentContextElement().getFileupload();

if(resource() != null)

wdComponentAPI.getMessageManager().reportSuccess(resource.getResourceName());

else{w

dComponentAPI.getMessageManager().reportWarning("Please upload the Document ");

}

} catch (Exception e) {

dComponentAPI.getMessageManager().reportWarning(e.getMessage());

}

0 Kudos

Hi,

I am working on SAP NetWeaver Mobile 7.1

Regards,

Narayani

former_member193726
Active Participant
0 Kudos

Hi Narayani,

What type of file are you trying to upload? Is that an XML file? Can you try checking the other file formats like word, excel, etc...

Regards,

Rekha Malavathu

0 Kudos

Hi,

I tried all the extensions, I get the same exception.

Regards,

Narayani

Former Member
0 Kudos

Check this:

// Appendix is the context node

IPrivateFreightRequestComponentView.IAppendixElement

element = wdContext.currentAppendixElement();

// if a file in the FileUpload field exists

if (element.getUploadFile() != null)

{

IWDResource resource = element.getUploadFile();

// get the size of the uploaded file => separate method

element.setFileSize(this.getFileSize(resource));

<b>// get the extension of the uploaded file

element.setFileExtension( resource.getResourceType().getFileExtension());</b>

// set context attribute 'fileName' .

element.setFileName(resource.getResourceName());

// set the details visibility attribute

element.setDetailsVisibility(WDVisibility.VISIBLE);

}

else

{

// if no file in the FileUpload field exists

}

0 Kudos

Hi,

Thanks for the reply.

I have tried all of this.

Whenever I click on the upload action even though i have not written no line of code I am getting a java.net.URISyntaxException, illegal character in query.

Regards,

Narayani

Former Member
0 Kudos

Hi Narayani,

Whether the file upload UI issue solved, kindly let me know that, i am also facing the similar problem.

Kindly help us

Thanks in Advance

Regards,

Chandran S

Former Member
0 Kudos

Hi,

Check if there are any space characters in your uploading path (file path).

First try to upload a file without any space characters in the uploading path(file path). If the problem is with the space characters then use the below encoding & decoding to resolve that issue.

Encoding while uploading the file:

// Getting the file resource
IWDResource resource = element.getCtx_va_FileResource();
//Getting the resource name
String resourceName = resource.getResourceName();
//Encoding the resource name
String encoderesourceName = java.net.URLEncoder.encode(resourceName,"UTF-8");

Again while downloading you can use decoder.

Hope this helps to resolve your issue.

See this below link.

Try this encoding even if there are no space characters.

Regards,

Charan

former_member193726
Active Participant
0 Kudos

Hi Narayani,

Can you try printing the catch block to the Web Dynpro view?

Also check if the view controller's fileupload attribute is mapped to the component controllers fileupload attribute.

Regards,

Rekha Malavathu

Former Member
0 Kudos

Hi,

Refer this link. U cau get a clear idea

/people/raja.thangamani/blog/2007/11/12/how-to-create-attachments-in-business-transaction-from-webdynprojava

Regards,

karthik.

0 Kudos

Hi,

Thanks for the info, I have gone through this link earlier and also tried the same way.

In my FileUpload UI element I dont see the data property.

Regards,

Narayani

Former Member
0 Kudos

Hi,

The data property will be the first property of FileUpload UI.

Try this link

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

Regards,

karthik