on 09-14-2006 1:09 PM
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
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
} }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got the same problem as yours.
Have you solved the issue ??
Would you please tell me how you solved this problem ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.