
imageshackapi - issue #13
Error code meaning: Wrong file type detected for file dog.jpg
What steps will reproduce the problem? 1. Using java HttpCore 4.0.1 2. 3.
What is the expected output? What do you see instead? I expect xml describing the successful upload.
What version of the product are you using? On what operating system? Using latest api constructs to form post on Windows 7 java 64bit.
Please provide any additional information below. I've been successful in creating an html page that submits locally with no problem but when I use java, I get this output:
<links> <error id="wrong_file_type">Wrong file type detected for file dog.jpg:</error> </links>
This is my java code if anyone can understand it:
HttpClient httpclient = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.imageshack.us/upload_api.php");
MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE, null, null);
FormBodyPart fbp = new FormBodyPart("fileupload", new FileBody(new File("F:\\temp\\dog.jpg"), "image/jpeg"));
entity.addPart(fbp);
FormBodyPart fbp2 = new FormBodyPart("key", new StringBody("3ACEIKNUede87aa4a0665d36868d7ba7bfc63101", MIME.DEFAULT_CHARSET));
entity.addPart(fbp2);
post.setEntity(entity);
post.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
post.addHeader("Accept-Language", "en-us,en;q=0.5");
//post.addHeader("Accept-Encoding", "gzip,deflate");
post.addHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
post.addHeader("Keep-Alive", "115");
post.addHeader("Connection", "keep-alive");
System.out.println(post.getRequestLine());
HeaderIterator hiter = post.headerIterator();
while(hiter.hasNext()) {
System.out.println(hiter.next());
}
System.out.println(entity.getContentEncoding());
System.out.println(entity.getContentType());
System.out.println(entity.getContentLength() + "");
try {
entity.writeTo(System.out);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//System.out.println(fbp.getHeader());
//System.out.println(fbp2.getHeader());
try {
HttpResponse httpresponse = httpclient.execute( post );
for(int i = 0; i < httpresponse.getAllHeaders().length; i++) {
org.apache.http.Header hd = httpresponse.getAllHeaders()[i];
//System.out.println(hd);
}
String response = EntityUtils.toString( httpresponse.getEntity(), "UTF-8" );
HttpEntity resEntity = httpresponse.getEntity();
resEntity.consumeContent();
System.out.println(response);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
//httpclient.getConnectionManager().shutdown();
}
I guess I want to understand what that error means so I can figure out what to do on the java end. Been spinning my wheels trying this and that but to no avail.
Thanks, Minh
- ImageShackFileUploader.java 5.15KB
Comment #1
Posted on Oct 22, 2011 by Swift RabbitThat exact code works for me. You might want to make sure (new File("F:\temp\dog.jpg") actually points to the file you think it points to.
Status: New
Labels:
Type-Defect
Priority-Medium