cancel
Showing results for 
Search instead for 
Did you mean: 

Problems in uploading file in KM through Webdynpro

Former Member
0 Kudos

Hi Guys,

I have a problem here after uploading a file to KM from a webdynpro application. I have written the following code for this purpose.

The problem is that, the file is getting uploaded properly with correct size but when I open it, it shows a message "Unsupported File Format" and then the file comes up blank without any data. The most logical problem could be mimetype setting, but this also I feel I have taken care of.

Please have a look and tell me if I am going wrong somewhere.

Thanks in advance.

-



try {
		/*
		 * Getting the user
		 */
		IUser sapUser = WDClientUser.getCurrentUser().getSAPUser();
		com.sapportals.portal.security.usermanagement.IUser ep5User = null;
		try {
			ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
		} catch (UserManagementException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		}
		/*
		 * Getting the Resource
		 */
		ResourceContext resContext = new ResourceContext(ep5User);
		/*
		 * Path to KM Folder
		 */
		RID pathKMFile = RID.getRID("/documents/FsapPOC/");
		IResourceFactory resFactory = null;
		ICollection parentDirectory = null;
		try {
			resFactory = ResourceFactory.getInstance();
			parentDirectory = (ICollection) resFactory.getResource(pathKMFile, resContext);
		} catch (ResourceException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
			return false;
		}
		IContent objContent = null;
		try {
			try {
				IMutablePropertyMap propertyMap = new MutablePropertyMap();
				ByteArrayInputStream bytArrIpStream = new ByteArrayInputStream(this.getByteArray(wdContext.currentContextElement().getResFileAttachmentUpload().read(false)));
							
				objContent = new Content(bytArrIpStream,wdContext.currentContextElement().getResFileAttachmentUpload().getResourceType().getHtmlMime(),bytArrIpStream.available());
						

                             IResource resource = parentDirectory.createResource(wdContext.currentContextElement().getResFileAttachmentUpload().getResourceName(),propertyMap,objContent);
							
			} catch (NotSupportedException e7) {
				// TODO Auto-generated catch block
				wdComponentAPI.getMessageManager().reportSuccess("NotSupportedException #### - "+e7.getMessage());
				return false;
			} catch (AccessDeniedException e7) {
				// TODO Auto-generated catch block
				wdComponentAPI.getMessageManager().reportSuccess("AccessDeniedException #### - "+e7.getMessage());
				return false;
			} catch (ResourceException e7) {
				// TODO Auto-generated catch block
				wdComponentAPI.getMessageManager().reportSuccess("ResourceException #### - "+e7.getMessage());
				return false;
			}
			
		} catch (IOException e6) {
			// TODO Auto-generated catch block
			e6.printStackTrace();
			return false;
		}
	 
		 } catch (WDUMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		  }

-


Eagerly awaiting any answers from you guys.

Regards,

Jitendra Chaudhari

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi ,

You have to define the encoding type as UTF-8 while retrieving the file.

Regards

Bharathwaj

Former Member
0 Kudos

Hi Bharathwaj,

I am not retrieving the file. My aim is just to upload the file in KM. What I am saying is that after this upload, if I go and view this file in KM itself it gives me this unsupported type exception.

Regards,

Jitendra.