Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7165387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:13:50+00:00 2026-05-28T14:13:50+00:00

I am trying to POST an image to imageshack using their API and Play

  • 0

I am trying to POST an image to imageshack using their API and Play Framework’s WSRequest object.

My code is as follows:

public static void upload( Picture picture ) throws Exception {

    //set file parameter - in this case the image
    WS.FileParam fp = new WS.FileParam( picture.asFile, "fileupload");

    //set other parameters
    Map<String,Object> params = new HashMap<String, Object>();
    params.put( "optsize", "resample" );
    params.put( "rembar", "yes" );
    params.put( "public", "no" );
    params.put( "a_username", username );
    params.put( "a_password", password );
    params.put( "key", a_key );

    //POST request
    Document doc = WS.url( "http://www.imageshack.us/upload_api.php" )
        .setHeader( "Content-Type", picture.contentType )
        .mimeType( "multipart/form-data" )
        .params( params )
        .files( fp )
        .post()
        .getXml();
}

However, I always reveive the following response from imageshack:

Sorry, but we’ve detected that unexpected data is received. Required parameter ‘fileupload’ is missing or your post is not multipart/form-data.

I have tried sending the file as a parameter using a byte array:

params.put( "fileupload", Base64.encode( picture.asBytes )  )

But this also results in the same response from Imageshack.

This is driving me mad. Can anyone point out where I am going wrong or possibly point me in the direction of a better solution? Thanks.


The cause

After a bit of research I found that I had neglected a bit of important information from this question….I am including the Google App Engine module within my app.

According to the Play Framework Google Group the code associated with attaching Files to a WS request when using GAE is actually just commented out. Hence the reason it just doesn’t work. So no error thrown for you and no indication why it doesn’t work…you just have to work it out.

I have accepted @Gary’s answer as it is the correct way to upload an image to imageshack using WS – just not when using GAE.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:13:51+00:00Added an answer on May 28, 2026 at 2:13 pm

    I don’t think you need to specify the content type or mime type directly.

    I used the following code to upload successfully.

    WS.FileParam fp = new WS.FileParam(
          new File("d:\\workspace\\ImageShackTest\\sample_picture.png"), "fileupload");
    
        Map<String,Object> params = new HashMap<String, Object>();
        params.put( "optsize", "resample" );
        params.put( "rembar", "yes" );
        params.put( "public", "yes" );
        //params.put( "a_username", username );
        //params.put( "a_password", password );
        params.put( "key", API_KEY );
    
        //POST request
        Document doc = WS.url( "http://www.imageshack.us/upload_api.php" )
            .params( params )
            .files( fp )
            .post()
            .getXml();
    

    I think when you attach a file to a request it automatically decides its going to be multipart/form-data.

    This is my entire controller (except for the API Key)

    package controllers;
    
    import play.*;
    import play.mvc.*;
    import java.util.*;
    import models.*;
    import play.libs.*;
    import java.io.File;
    
    public class Application extends Controller {
    
        public static void index() { render(); }
    
        private static final String API_KEY = "API KEY REMOVED TO PROTECT THE INNOCENT";
    
        public static void tryUpload() {
            WS.FileParam fp = new WS.FileParam( new File("d:\\workspace\\ImageShackTest\\sample_picture.png"), "fileupload");
    
            Map<String,Object> params = new HashMap<String, Object>();
            params.put( "optsize", "resample" );
            params.put( "rembar", "yes" );
            params.put( "public", "yes" );
            params.put( "key", API_KEY );
    
            String doc = WS.url( "http://www.imageshack.us/upload_api.php" )
                .params( params )
                .files( fp )
                .post()
                .getString();
    
            System.out.println(doc);
    
            index();
        }
    }
    

    and this is the application.conf file

    # This is the main configuration file for the application.
    # ~~~~~
    application.name=ImageShackTest
    application.mode=dev
    %prod.application.mode=prod
    application.secret=JIVQE8y3y1lCzXRGprFJvoXBdi8Jpa8qE1U1mBIooLLOOYk5yyhAI5cxbEf4q4pl
    date.format=yyyy-MM-dd
    attachments.path=data/attachments
    mail.smtp=mock
    

    I didn’t make any other changes. Just browsed to http://localhost:9000/Application.tryUpload and could see the success XML on the play console.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to post an image to TwitPic.com using their API. However, I have
I'm trying to post some code on a blog using the pre tag. Something
I'm trying to post a Facebook status update, using the Facebook iOS API, with
I am trying to upload images to ImageShack using the API. I think they
I'm trying to upload an image to imageshack using flex, but keep getting <links>
I'm trying to POST a http request using ajax, but getting a response from
I'm trying to post to a webpage using WebClient in C#. Somehow the parameters
I am trying to post a multi-part form using httplib, url is hosted on
i'm trying to post an image to my users's facebook wall once they hit
What I am trying to do is post an image that has been created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.