cancel
Showing results for 
Search instead for 
Did you mean: 

Upload a file from WD

Former Member
0 Kudos

Hello experts,

i am trying to implement a upload Ui Element from WD.

Unfortunately I have some problems with my Action "UploadFile".

Here ist the implemented Code-Section:

onActionFileUpload (com.sap.tc................wdEvent)

{

IPrivateUploadScreen.IContextElement element = wdContext.currentContextElement();

if (element.getFileResource()!=null){

IWDResource resource = element.getFileResource();

element.setFileSize(this.getFileSize(resource))

....

.....

This WD-App is based on the "Uploading and Downloading Files in Web Dynpro Java" Tutorial.

The Problem ist that method setFileSize isn't a member of the Object element.

Any ideas?

Regards Marco

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You need to have the following function in your controller.

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

Page 11.


//@@begin others
/** Read resource and calculate file size.
* @return the file size in Bytes, KB or MB as String */
private String getFileSize(IWDResource resource) {
InputStream stream = null;
DecimalFormat myFormatter = new DecimalFormat("###.##");
double size = 0;
String unit = "";
try {
stream = resource.read(false);
size = stream.available();
if (size < 1024) {
unit = " Bytes";
unit= } else if (size < 1048576) {
size = size / 1024;
unit = " KB";
unit= } else if (size < 1073741824) {
size = size / 1024 / 1024;
unit = " MB";
} } catch (IOException e) {
wdComponentAPI.getMessageManager().reportException(
e.getLocalizedMessage(), true);
} finally {
iftream != null) {
(s try {
stream.close();
} catch (IOException e) {
wdComponentAPI.getMessageManager().reportException(//@@end

Regards

Ayyapparaj

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi,

The Problem ist that method setFileSize isn't a member of the Object element.

according to the tutorial the "setFileSize" is attribute defined under root context.

and the getFileSize() is method defined in java code area . you can find it in tutorial.

i think you confused with it.

hope it clear.

Regards,

ramesh

Edited by: Ramesh Babu V on Oct 16, 2008 6:19 PM

Former Member
0 Kudos
Former Member
0 Kudos

Hi,

I had used the following code for file upload. Check this it may be helpfull to you

InputStream text=null;

String path;

int temp=0;

IPrivateUploadView.IContextElement element1 = wdContext.currentContextElement();

IWDResource resource = element1.getResource();

// element1.setFileName(resource.getResourceName());

// element1.setFileExtension(resource.getResourceType().getFileExtension());

try

{

File file = new File(".
temp
webdynpro
web
local
yh1245_ftp
Components
com.yash.yh1245.Upload
"wdContext.currentContextElement().getDirectoryName()"
"+wdContext.currentContextElement().getResource().getResourceName().toString());//created a new file in server

FileOutputStream op = new FileOutputStream(file);

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

{

text=wdContext.currentContextElement().getResource().read(false);

while((temp=text.read())!=-1)

{

op.write(temp);

}

}

op.flush();

op.close();

path = file.getAbsolutePath();

path1=file.getAbsolutePath();

String path2=file.getPath();

wdComponentAPI.getMessageManager().reportSuccess("File Path is "+path);

// IWDConfirmationDialog cWin =wdComponentAPI.getWindowManager().createConfirmationWindow("File is uploaded"+path2,wdThis.wdGetAPI().getViewInfo().getViewController().findInEventHandlers("Ok"),"Ok");

// cWin.open();

}

catch(Exception e)

{

wdComponentAPI.getMessageManager().reportException(e.getMessage(),false);

}

Regards

Raghu

former_member192434
Active Contributor
0 Kudos

Hi Marco,

You have to create IWDREsource type as follow

IPrivateFTPUpload.IContextElement element = wdContext.currentContextElement();

IWDResource resource = element.getResourceURL();

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

and getResourl is context which type is as follow.

type com.sap.ide.webdynpro.uielementdefinitions.Resource

Hope this will solve the problem

Thanks

Anup

Edited by: Anup Bharti on Oct 16, 2008 8:08 AM

Former Member
0 Kudos

hi,

You can refer the document mentioned below. If you really go through the doc step by step , you wont face any problem.

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

May be for Setfilesize, you havent created a context.

Do check the same for all the elements.

like FileExtension

Filename

DetailsVisibility ........

vmadhuvarshi_
Contributor
0 Kudos

Marco,

setFileSize is not a mamber of object element as it refers to current Element of the context. Similarly, FileExtension, Filename and DetailsVisibility are not members of element, but elements in Context.

IPrivateUploadScreen.IContextElement element = wdContext.currentContextElement();

This statement gives you current context element and when you refer to element.set******, you are actually referring to elements of current context element.


// get the size of the uploaded file
element.setFileSize(this.getFileSize(resource));
// get the extension of the uploaded file
element.setFileExtension( resource.getResourceType().getFileExtension());
// set context attribute 'fileName' .
element.setFileName(resource.getResourceName());
// set the details visibility attribute
element.setDetailsVisibility(WDVisibility.VISIBLE);

For all element.set*****, there should be elements available in context. You should get them as part of initial project template. If not, just create these elements and you should be good.

Hope this helps.

Vishwas