Skip to Content
author's profile photo Former Member
Former Member

Urgent!--Upload image using java API

Hi ppl,

I am working on MDM SP3. I want to upload images using java api. I tried the following code.

catalog = new CatalogData();            
int resultLogin = catalog.Login(hostname, port,username,password, language);
		
byte[] imageBuf = readFile("C:\temp\bus.bmp");

 A2iFields fields = new A2iFields();
fields.Add(new A2iField("Data ID", new Value         (imageBuf))); 
 fields.Add(new A2iField("Name", new Value("pic.bmp")));

 fields.Add(new A2iField("Original Name", new Value("bus.bmp"))); 
 fields.Add(new A2iField("Data Group ID", new Value(1)));
int origLocationId = 0;
try {
  origLocationId =
   catalog.AddDataLocation("C:\temp\bus.bmp",0,DataLocationType.RemovableMediaLocation);
	} catch (StringException e2) {
	e2.printStackTrace();
	}
fields.Add(new A2iField("Original Location ID", new Value(origLocationId))); 
fields.Add(new A2iField("Has Original", new Value(true)));

 String imageTable = "Images";
	try {
        catalog.AddRecord(imageTable, fields, -1, -1);
	} catch (StringException e) {
	e.printStackTrace();
	System.out.println(e.GetErrorCode());
	System.out.println(e.GetRCMessage(e.GetErrorCode()));
		e.A2iPrintError();
	}

But it throws the following error

a2i.core.StringException: AddRecord error

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

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

at MDMCon.MDMTest.main(MDMTest.java:88)

-2147483647

No message for RC (0x80000001)

Error code: 0x80000001

Error message : No message for RC (0x80000001)

Help me solve this issue

its very Urgent

Vijay

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 11, 2006 at 08:47 AM

    Hi Vijay,

    The return code (2147483647) is a "bad parameter" code (see the file constant-values.html which is part of the javadoc package of the MDM4J API).

    Walter

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi, Walter!

      These fragments of code are identical (StringException.GetRCMessage just invokes corresponding method in class RC):

      public class StringException
      ...
      ...
          public static String GetRCMessage(int i)
          {
              return RC.GetTextForError(i);
          }
      
          public static String GetRCMessage(int i, LanguageOrder languageorder)
          {
              return RC.GetTextForError(i, languageorder);
          }
      ...
      ...
      

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 10:02 AM

    Hi, Vijayasarathy Raghunathan.

    To resolve the problem with undefined messages for return codes:

    LanguageOrder lo = catalog.GetLanguageOrder();
    String rcMessage = RC.GetTextForError( rc, lo );
    

    OR (for example to translate RC of unsuccessful login):

    1) Create "dummy" implementation of interface LanguageOrder:

    import a2i.core.LanguageOrder;
    import java.util.ResourceBundle;
    
    
    public class EnglishLanguageOrder
    	implements LanguageOrder
    {
    	public EnglishLanguageOrder()
    	{
    	}
    
    	public String GetString(String s, String s1)
    	{
    		return getStringEnglish(s, s1);
    	}
    
    	public static String getStringEnglish(String s, String s1)
    	{
    		String s2 = s + "_" + "en";
    		String s3 = ResourceBundle.getBundle(s2).getString(s1);
    		return s3;
    	}
    }
    

    2) get a message in English:

    String rcMessage = RC.GetTextForError( rc, new EnglishLanguageOrder() );
    

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.