- Topics: Active | Unanswered
Pages: 1
Topic closed
#1 2010-01-11 17:58:02
- **_km70569w_**
Upload file using Connect Pro API in java
Hi,
I am struggling to upload a file to connect pro using Java. I pass in filename to the program using shell script as
./uploadFile.sh c:/test.jpg
this invokes my java main class called uploadFile where I create session and login to the server. I get the sco-id for the target folder and then call uploadSco(File file) where I pass in a file instance of that file. I am getting response as below.
<results>
<status code="invalid">
<invalid field="file" type="string" subcode="missing"/>
</status>
</results>
Can any one give me some hints or sample code to do this?
Thanks.
KM
Offline
#2 2010-01-11 21:39:07
- **_km70569w_**
Re: Upload file using Connect Pro API in java
Looks like I am not making any sense with my question.
I am just not sure how to upload a file using the the API from java program. I do not have a form to upload a file. I am calling this program from a shell script as mentioned. I pass the file absolute path and then create a file object from that filename. But now, I need to do two things. I need to call the API with sco-upload action. I pass in the param as below
http://hostname/api/xml?action=sco-upload&sco-id=43348&file=C:\contents\com.jpg&session=breezipyugcyv6h9452ux
I open the connection as
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
bos = new BufferedOutputStream(conn.getOutputStream());
bis = new BufferedInputStream(new FileInputStream(file));
int i;
while ((i = bis.read()) != -1 ) {
bos.write(i);
}
Document doc = new SAXBuilder(false).build(conn.getInputStream()); // to get the response
Element element = doc.getRootElement();
Every time I get error message
<results>
<status code="invalid">
<invalid field="file" type="string" subcode="format"/>
</status>
</results>
Am I doing this right? Am I missing something. Can anyone help? if you need more clarification please let me know. Thanks.
KM
Last edited by **_km70569w_** (2010-01-11 21:54:08)
Offline
Pages: 1
Topic closed