Skip to Content
Former Member
Apr 29, 2009 at 11:27 AM

Creating new File via KM Java API


Hello All,

I have a problem by creating a new ressource via the java api of the km. The szenario is the following one:i create a picture dynamically with java in the application after generating the picture i write it into en outputstream and want to save it over the km java api into a special folder in the km. The file appears in the km correctly but if i try to open it or to download it i get an failure, most of the time an internal 500, so the file seems to be corrupt.

At the next step i tried it with an definitily not corrputed picture, by reading this on into an fileinputstream and pass this inputstream over to the km, but still the same issue. The file is there but i cant open it.

Here are the lines of code for access km and create the ressource:

public static void writeFileIntoKM (InputStream file, String fileName) {
		RID pathRID = RID.getRID("/documents/OMDOCSPACE/lab/ActivityRecorder"); 	
		try {
			IUser serviceUser = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");

			ResourceContext resourseContext = new ResourceContext(serviceUser);
			IResourceFactory resourseFactory = com.sapportals.wcm.repository.ResourceFactory.getInstance();
			ICollection collection = (ICollection)resourseFactory.getResource(pathRID, resourseContext);
			//Read the File
			InputStream stream = file;
			String resourceName = fileName;
			//KM Content
			Content cont = new Content(stream,"image/png",-1,null);
			//create a file in above mentioned path in KM
			com.sapportals.wcm.repository.IResource new_resource = (com.sapportals.wcm.repository.IResource)collection.createResource(resourceName, null, cont);
		} catch (ResourceException e) {
		} catch (UserManagementException e) {
		} catch (ContentException e) {

Has anybody an idea what i'm doing wrong?

Best regards,