Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Help please to Upload a file from my PC to server's KM

Hello:

I can't Upload correctly a file from my local PC to a KM of the server.

My problem is after that I've uploaded my selected file to KM, when I open or download it from the KM appears blank. I can't get the file Data of the file for uploading

I use a FileUpload.

____________________

<b>

My Context:

File (node)
     |----fileResource  (com.sap.ide.webdynpro.uielementdefinitions.Resource)
     |----fileData  (binary)    
     |----fileName  (String)

</b>

________________________________

wdDoInit(){
     IPrivateUploadDownloadKMView.IFileElement fileBind = wdContext.createFileElement(); 
     wdContext.nodeFile().bind(fileBind); 

     IWDAttributeInfo attInfo = wdContext.nodeFile().getNodeInfo().getAttribute("fileData"); 
     ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
}

onActionSubir(){
      IPrivateUploadDownloadKMView.IFileElement fileElement = wdContext.currentFileElement();
      IWDResource resource = fileElement.getFileResource();

      fileElement.setFileName(resource.getResourceName());
      fileElement.setFileData(fileData);

      byte[] fileData=new byte[resource.read(false).available()];
			 
      fileElement.setFileData(fileData);

      fileName = fileElement.getFileName();
			 
     try{			 
           File file = new File(fileName); 
           FileOutputStream out = new FileOutputStream(file); 
           out.write(fileElement.getFileData()); 
           out.close(); 

           fin = new FileInputStream(fileName); 
           fin.read(); 
			 
           Content content = new Content(fin,null, -1); 
            IResource newResource = folder.createResource(fileElement.getFileName(),null, content);
      }
      catch(Exception e){
             IWDMessageManager mm = wdControllerAPI.getComponent().getMessageManager();
             mm.reportWarning("error: "+e.getMessage());
      }
}

Can you help me?, any sugestions to solve my problem or improve my code?

Regards

Jonatan.

Former Member
Not what you were looking for? View more on this topic or Ask a question