cancel
Showing results for 
Search instead for 
Did you mean: 

Web Dynpro file upload - invalid characters in file name

Former Member
0 Kudos

Hello,

I'm using web dynpro file upload:

  
public void onActionUpload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionUpload(ServerEvent)
      try {
         final IWDResource fileResource =
          wdContext.currentContextElement().getFileResource();
         final String fileName = fileResource.getResourceName();

      // catch the file and store it into KM repository

      } catch (Exception e) {
         // log error
      }
}

But when uploading file with national characters in file name, KM repository complains on bad file name (invalid characters). When I write file name into log (as a debug message), there is every national character replaced by '?' (question mark). I supposed that it is only in wrong encoding/viewing, so I tried some encoding miracles and after that I tried to print out the file name as byte sequence - unfortunately the file name contains directly ASCII 63 characters = '?' (QM). It means, that something before must change and corrupt this filename during file upload process (web dynpro framework?).

Have you anybody some exerience with uploading files via web dynpro using national characters in file name?

Thank you

Martin

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I use this function to upload files, and it also good for files names in hebrew. I don't do anything special regard enconding because web dynpro uses unicode.

resourceAttribute - The name of the attribute that contains the file content (binary)

nameAttribute - The name of the attribute that contains the file name (string)

node - The node that contains both attributes

public void uploadFile( com.sap.tc.webdynpro.progmodel.api.IWDNode node, java.lang.String resourceAttribute, java.lang.String nameAttribute)

{

//@@begin uploadFile()

//get modifiable binary type from the attribute info,

// requires type cast.

IWDModifiableBinaryType binaryType =(IWDModifiableBinaryType) node.getNodeInfo().getAttribute(resourceAttribute).getModifiableSimpleType();

IWDNodeElement element = node.getCurrentElement();

String filename = element.getAttributeAsText(nameAttribute);

if (filename.trim().equals(""))

return;

try{

//Get an object of current Portal user

IWDClientUser wdClientUser = WDClientUser.getCurrentUser();

com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();

// create an ep5 user from the retrieved user

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

ResourceContext context = new ResourceContext(ep5User);

//Give the path to KM in the variable path

String repository = "/documents/DocNews/";

RID rid = RID.getRID(repository);

IResourceFactory factory = ResourceFactory.getInstance();

ICollection folder = (ICollection) factory.getResource(rid,context);

byte [] byteArray = (byte[])wdContext.currentNewMessageElement().getAttributeValue(resourceAttribute);

//From the temporary location read the file using an input stream

ByteArrayInputStream fin = new ByteArrayInputStream(byteArray);

//Using this input stream we can write to the repository

Content content = new Content(fin,binaryType.getMimeType().getHtmlMime(), -1L);

try{

IMutablePropertyMap propertyMap = new MutablePropertyMap();

IResource newResource = folder.createResource(wdContext.currentNewMessageElement().getAttributeAsText(nameAttribute), propertyMap, content);

}catch (NameAlreadyExistsException re2){

try{

fin = new ByteArrayInputStream(byteArray);

content = new Content(fin,binaryType.getMimeType().getHtmlMime(), -1L);

RID fileRid = RID.getRID(repository + filename);

IResource fileResource = factory.getResource(fileRid,context);

fileResource.updateContent(content);

}catch(Exception e){

wdComponentAPI.getMessageManager().reportSuccess("File doesn't exist:"+e.getMessage());

}

}

fin.close();

}catch(Exception e){

wdComponentAPI.getMessageManager().reportException("File not found."+e.getMessage(),true);

}

finally{

element.setAttributeValue(resourceAttribute,null);

element.setAttributeValue(nameAttribute,null);

}

//@@end

} }

Former Member
0 Kudos

I got the same problem as yours.

Have you solved the issue ??

Would you please tell me how you solved this problem ?