Export to GitHub

imageshackapi - issue #13

Error code meaning: Wrong file type detected for file dog.jpg


Posted on Jul 3, 2010 by Massive Lion

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&quot;);

    MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE, null, null);

    FormBodyPart fbp = new FormBodyPart(&quot;fileupload&quot;, new FileBody(new File(&quot;F:\\temp\\dog.jpg&quot;), &quot;image/jpeg&quot;));
    entity.addPart(fbp);

    FormBodyPart fbp2 = new FormBodyPart(&quot;key&quot;, new StringBody(&quot;3ACEIKNUede87aa4a0665d36868d7ba7bfc63101&quot;, MIME.DEFAULT_CHARSET));
    entity.addPart(fbp2);
    post.setEntity(entity);

    post.addHeader(&quot;Accept&quot;, &quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&quot;);
    post.addHeader(&quot;Accept-Language&quot;, &quot;en-us,en;q=0.5&quot;);
    //post.addHeader(&quot;Accept-Encoding&quot;,  &quot;gzip,deflate&quot;);
    post.addHeader(&quot;Accept-Charset&quot;, &quot;ISO-8859-1,utf-8;q=0.7,*;q=0.7&quot;);
    post.addHeader(&quot;Keep-Alive&quot;, &quot;115&quot;);
    post.addHeader(&quot;Connection&quot;, &quot;keep-alive&quot;);

    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() + &quot;&quot;);
    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 &lt; httpresponse.getAllHeaders().length; i++) {
            org.apache.http.Header hd = httpresponse.getAllHeaders()[i];
            //System.out.println(hd);
        }


        String response = EntityUtils.toString( httpresponse.getEntity(), &quot;UTF-8&quot;  );
        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

Attachments

Comment #1

Posted on Oct 22, 2011 by Swift Rabbit

That 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