cancel
Showing results for 
Search instead for 
Did you mean: 

Image upload using Java API

Former Member
0 Kudos

Hi all,

I am trying to upload an image into MDM repository using the Java MDM4J API. I have referred to the earlier posting in this forum for the same problem . However I am working on SP3 version of MDM software and looks like the Images table structure changed a bit and the code in the earlier posting isn't working.

I am getting an error code <b>-5586944</b> and the message that gets printed on the console is

<i>a2i.core.StringException: AddRecord error

at a2i.common.CatalogData.AddRecord(Unknown Source)

at a2i.common.CatalogData.AddRecord(Unknown Source)</i>

Here is the code that I am using to upload the image


String filePath = "C:\temp\Sunset.jpg";
File file = new File(filePath);
byte[] bytes = new byte[(int) file.length()];

try{
	//read byte from file, and set the large data
	FileInputStream inputStream = new FileInputStream(file);
	inputStream.read(bytes);
	mdmFields.Add(new A2iField("Data ID", new Value(bytes)));
}catch(IOException ioex){
	ioex.printStackTrace();
}

int dataGroupId = 0;//Hardcoded it to 0. There is one group already in the repository
mdmFields.Add(new A2iField("Data Group ID", new Value(dataGroupId)));

//adding the name
mdmFields.Add(new A2iField("Name", new Value(file.getName())));
mdmFields.Add(new A2iField("Original Name", new Value(file.getName())));

//adding OrigLocationId
int origLocationId =0;
try{
	origLocationId = catalog.AddDataLocation(filePath, 0, DataLocationType.ComputerLocation);
	System.out.println("Location id generated is " +origLocationId);
}catch(StringException ex){
	System.out.println("Error while generating the location id");
	ex.printStackTrace();
}

mdmFields.Add(new A2iField("Original Location ID", new Value(origLocationId)));

try {
	//adding the image to the "Images" table
	int newImageId = catalog.AddRecord("Images", mdmFields, 0, 0);
} catch (StringException e) {
	// TODO Auto-generated catch block
	System.out.println("Error while adding the image record " + e.GetErrorCode() + "  " + e.GetRCMessage(e.GetErrorCode()));
	e.printStackTrace();

}


I am not able to figure out what is causing the problem. Any ideas would be greatly helpful. Thanks in advance.

Suman.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Suman,

If you look at the description for the error code, you get RC_CM_DATAGROUPNOTFOUND.

Try giving some other value ( 1 worked for me ) in the Data Group or try following the code given for the Data Group in other forum post that you have mentioned.

Regards,

Mausam

Former Member
0 Kudos

Thanks for your help. I was actually looking for a place where I can understand what the error code meant. By the way where did find this information on what the errror code stands for?

Former Member
0 Kudos

Suman,

If you have ZIP file for MDM4J APIs like MDM4J_Ver5.5...zip ( MDM SP4- MDM4J_Ver5.5.33.13.zip). There is a file called "constant-values.html" in Javadoc directory. All the error codes are given there.

Hope this helps.

Regards,

Mausam

Former Member
0 Kudos

about error codes something was mentioned in .

Former Member
0 Kudos

Hi Mausam,

Thanks for your help. However, the problem doesn't seem to be going.

I printed the records in the <b>Data Groups</b> table using a program to find the record ids that are already existing. My Data Groups table has 3 records. Here are the values.

ID :1 Value :MyGroup

ID :2 Value :Group2

ID :3 Value :Group3

I tried passing all the above 3 values (1,2,3) as input to the <b>Data Group ID</b> field. However, this time, I am getting a different error code this time

Error while adding the image record -2147483647  No message for RC (0x80000001)
a2i.core.StringException: AddRecord error
	at a2i.common.CatalogData.AddRecord(Unknown Source)
	at a2i.common.CatalogData.AddRecord(Unknown Source)
	at images.MyImageUpload.uploadImage(MyImageUpload.java:82)

The error code <b>2147483647</b> from the javadocs says <b>RC_BADPARAM</b>. Not able to figure out what exactly is causing the problem with Data Group ID.

Any ideas or pointers to solve this would be greatly helpful. Thanks in advance.

Regards

Suman

> Hi Suman,

>

> If you look at the description for the error code,

> you get RC_CM_DATAGROUPNOTFOUND.

>

> Try giving some other value ( 1 worked for me ) in

> the Data Group or try following the code given for

> the Data Group in other forum post that you have

> mentioned.

>

> Regards,

> Mausam

Former Member
0 Kudos

Hi Suman,

I found the cause of this error. In the MDM Console you should change the following:

Right-Click on the Repository and select Properties...

In this window change the value of the following:

Allow invalid images -> Yes

You may first have to change the setting Prohibit Photoshop Images -> No

Former Member
0 Kudos

Hi Leo Van Hengel,

Thanks a lot for your help. It didn't even occur to me that there will be such a property for the repository which needs to be changed.

I am now able to run my code successfully and upload the image successfully into the repository. However, I have a few more questions / problems

1. The images i am uploading are not invalid ones. Then why did we have to change the setting allow invalid images to Yes? Is this a bug in the product?

2. I uploaded the image using the java code. When I tried to see the Image using the Image Manager, it is showing the record but showing the Image as <b>Loading Image</b>. However it is never showing the image. I tried to identify the differences between the records uploaded using the Image Manager and the Java program and identified two differences.

2.1 <b>Data Size</b> field is showing <b>0</b> for image uploaded with java code. I tried to set the Data Size using the following code

	String filePath = "C:\temp\Sunset.jpg";
	File file = new File(filePath);
        ...........
        ...........
        mdmFields.Add( new A2iField("Data Size", new Value(file.length()) ));

Is something wrong with the above code? Am I going in the correct direction?

2.2 <b>Has Thumbnail</b> field has <b>false</b> for the image uploaded with java code. I didn't how to set this field to true or rather how to generate thumbnail to the uploaded image. Any pointers on this will be very helpful.

Thanks in advance.

Suman

Former Member
0 Kudos

Hi Suman,

I am also struggling with some of the issues you still have, but i will try to answer your questions:

1. I am not sure about this, i also know that my images are valid ones, but i think the API is maybe failing somewhere if it tries to determine the image-type, maybe for generating the thumbnail or something like that. With the setting allow invalid images your now able to store any filetype in the repository.

I noticed that for PDFs you should also apply the same setting in the MDM Console even if your uploading PDFs with the Data Manager. This is because it needs Adobe Acrobat to generate a preview.

2. I cannot set the Data Size for images either, with uploading PDFs with the API this works fine, by using your code.

Also generating thumbnail is not working form the API. Only after performing "Generate Thumbnail" in the Data Manager on the uploaded recorded the thumbnail is generated and the Data Size is calculated correctly, but there is no equal API call for that as far as i know.

So i think there are still some issues with uploading images with the API, i hope somebody else can give us an answer about these problems?

Regards,

Leo

Former Member
0 Kudos

Thanks Leo for posting the information that you have.

> 1. I am not sure about this, i also know that my

> images are valid ones, but i think the API is maybe

> failing somewhere if it tries to determine the

> image-type, maybe for generating the thumbnail or

> something like that. With the setting allow invalid

> images your now able to store any filetype in the

> repository.

I have referred to MDM Data Console Reference document. It states that the image is considered invalid if for some reason Thumbnail can't be generated. So your guess is correct. But I am not sure why the thumbnail generation is failing....

> 2. I cannot set the Data Size for images either, with

> uploading PDFs with the API this works fine, by using

> your code.

Looks like both these are problems in the API. Can someone from <b>SAP MDM</b> provide any information about these problems in the MDM4J API. If these are not bugs, could you please suggest a way to solve these issues.

Thanks

Suman