cancel
Showing results for 
Search instead for 
Did you mean: 

File UpLoad Issue

former_member193726
Active Participant
0 Kudos

Hi All,

I have a specific requirement with respect to FileUpload UI Element.

I have been able to upload the files without any problem, but the requirement which I have is somewhat unique.

I want the files to be put under a particular folder on the Web Application Server.

Hence I need to create the folder first and then place the file that I am trying to upload.

Would request anyone to help me in this regard.

Thanks,

Rekha Malavathu

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Mukesh,

I ahve created the alias in the server

String docuurl= "<server>:<port>/xyz/ehs/" + fname;

here xyz/ehs is the alias.

file is a binary attribute.

Thanks,

Lakshmi.

Former Member
0 Kudos

Hi

You have to specify the server location where you have to upload the file

1.Goto Visual Administrator->Http Provider->Aliases in the Runtime Tab.

Give the alias name as "file" and give the server folder where you want to upload the file.

for eg:

c:/My Documents/

Kind Regards

Mukesh

Former Member
0 Kudos

Hi,

Please tell me how to upload file from local machine.

I have successfully uploaded files by using File Upload UI element where I am able to select the required file.

Now I have a requirement of picking up a file from desktop using the code.

If I am simply giving the path "C:
Folder\file.txt", it is searching on server.

Thanks!!

Anubha

Former Member
0 Kudos

Hi Mukesh,

I could not Upload the file.

Thanks,

Lakshmi,.

Former Member
0 Kudos

Hi

You have to create alias for your server psth in visual admin in the name of "file"

see this thread

Kind Regards

Mukesh

Former Member
0 Kudos

The error message is

The properties for destination file of type HTTP could not be located.

Yeah I am done with the DOINIT part.

Thanks,

Lakshmi.

Former Member
0 Kudos

Hi Mukesh,

I followed the steps as u mentioned in this thread for uploading a file to a specific location in the server. I created a folder in the server and written the code as u specified. But I am getting an exception for the destination. I wrote the code as

byte imgsource[]=wdContext.currentFileElement().getFile();

String filePath=wdContext.currentFileElement().getString();

wdComponentAPI.getMessageManager().reportSuccess(wdContext.currentFileElement().getString());

byte[] fileBytes; //an array of bytes

wdComponentAPI.getMessageManager().reportSuccess("hai");

try {

File files=new File(filePath);

String fname=files.getName();

final InitialContext ctx1 = new InitialContext();

final DestinationService dstService1 = (DestinationService)ctx1.lookup(DestinationService.JNDI_KEY);

final Destination destination = dstService1.getDestination("HTTP","file");//specify the Http destination as document

fileBytes = imgsource; //create a byte array from contents of field

String docuurl= "http://<server>:<port>/<alias>/" + fname;

OutputStream targetFile= new FileOutputStream(docuurl); // define the output stream

targetFile.write(fileBytes); //write the array of bytes to file

targetFile.close(); //close the File stream

}

catch (DestinationException e) {

// TODO Auto-generated catch block

e.printStackTrace();

wdComponentAPI.getMessageManager().reportSuccess("u r in first catch");

}

catch (RemoteException e) {

// TODO Auto-generated catch block

e.printStackTrace();

wdComponentAPI.getMessageManager().reportSuccess("second catch");

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

wdComponentAPI.getMessageManager().reportSuccess("third catch");

}

catch (NamingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

wdComponentAPI.getMessageManager().reportSuccess("fourth catch");

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

wdComponentAPI.getMessageManager().reportSuccess("fifth catch");

}

}

Here File(value attribute) contains the BINARY Data of the file.

I am getting the exception as "u r in first catch". Please help me on this.

Thanks in advance,

Lakshmi.

Former Member
0 Kudos

Hi

Please post the error message

wdComponentAPI.getMessageManager().reportSuccess("u r in first catch"+e.getMessage());

Try this in the DoInit() part

IWDAttributeInfo attInfo = wdContext.nodeSeparateImgnode().getNodeInfo().getAttribute(IPrivateCV_ClientReg_view_extra_table.ISeparateImgnodeElement.IMGSOURCE);

ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType =(IWDModifiableBinaryType)type; //(IWDModifiableBinaryType)attInfo.getModifiableSimpleType();

Kind Regards

Mukesh

Former Member
0 Kudos

Hi

Try this

Create node in the view UploadNode with

cardinality 1..n

selection 0..1

singleton true

Create an attribute document with type binary

Create an attribute filename with type string

bind the node to the UIElement File Upload

data UploadTestNode.document

fileName UploadTestNode.filename

In the view's

wdDoInit()

IWDAttributeInfo attInfo = wdContext.nodeUploadTestNode().getNodeInfo().getAttribute(IPrivateZ_CV_Docattachment_createView.IUploadTestNodeElement.DOCUMENT);

ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)type;

wdContext.currentContextElement().setAuthoriseshow(WDVisibility.NONE);

//The value of the file Upload UI element only valid in the particular view so by event handle you get the value of the document

create an action inside view as onActionSave

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

{

byte imgsource[]=wdContext.currentUploadTestNodeElement().getDocument();

String filePath=wdContext.currentUploadTestNodeElement().getFilename();

byte[] fileBytes; //an array of bytes

try{

File files=new File(filePath);

fname=files.getName();

final InitialContext ctx1 = new InitialContext();

final DestinationService dstService1 = (DestinationService)ctx1.lookup(DestinationService.JNDI_KEY);

final Destination destination1 = dstService1.getDestination("HTTP","document");//specify the Http destination as document

fileBytes = imgsource; //create a byte array from contents of field

String docuurl= http://<Server>:<port>/<alias>/+fname;

OutputStream targetFile= new FileOutputStream(docuurl); // define the output stream

targetFile.write(fileBytes); //write the array of bytes to file

targetFile.close(); //close the File stream

}catch(Exception e){

e.printStackTrace();

wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());

}

}

You have to specify the Http destination for the folder in WAS

1.Goto Visual Administrator->Http Provider->Aliases in the Runtime Tab.

2.Give the Alias Name and Path for the Folder.

see this Thread

Kind Regards

Mukesh