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

  • Home
  • SEARCH
  • 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 7583755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:45:31+00:00 2026-05-30T18:45:31+00:00

I am lost right now with trying to upload an image to my server.

  • 0

I am lost right now with trying to upload an image to my server. I am able to take the picture and get my location on the Android device. I have the follow code to upload the file to the server:

    public Boolean postFunction(File image) {
    String tag = "postFunction";

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(UPLOAD_URL);

    try {
        MultipartEntity entity = new MultipartEntity();

        entity.addPart("type", new StringBody("photo"));
        entity.addPart("data", new FileBody(image));
        httppost.setEntity(entity);
        HttpResponse response = httpclient.execute(httppost);
        Log.i(tag, "picture was uploaded " + response.toString());
        return true;

    } catch (ClientProtocolException e) {
        Log.e(tag, "Client: " + e.toString());
        return false;
    } catch (IOException e) {
        Log.e(tag, "IO: " + e.toString());
        return false;
    }
}

I pass the image file to this function and it does the upload. However the error lies on the server end I believe.

Here is my PHP code:

      public function upload() {
        //$type = $this->input->post('type');
        //$data = $this->input->post('data');

        $base = $_REQUEST['data'];

        echo $base;

// base64 encoded utf-8 string

        $binary = base64_decode($base);

// binary, utf-8 bytes

        header('Content-Type: bitmap; charset=utf-8');

// print($binary);
//$theFile = base64_decode($image_data);

        $file = fopen('./test.jpg', 'wb');

        fwrite($file, $binary);

        fclose($file);

        echo '<img src=test.jpg>';
    }

The file gets touched but still remain blank. Am I missing something here? Please help, I tried Googling this but came up with different results that did not help me much.

  • 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-30T18:45:32+00:00Added an answer on May 30, 2026 at 6:45 pm

    You can check one very good tutorial here.

    Also try following code,

    public class TryprojectActivity extends Activity {
        InputStream is;
        int pic_count = 0;
        Bitmap bitmap=null;
        FileInputStream in1,in2,in3;
        BufferedInputStream buf;
    
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
    
            try {
                in1 = new FileInputStream("/sdcard/1.jpg");
            } 
            catch (FileNotFoundException e2) {
            // TODO Auto-generated catch block
                e2.printStackTrace();
            }
    
            try {
                in2 = new FileInputStream("/sdcard/2.jpg");
            } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } 
    
        try {
            in3 = new FileInputStream("/sdcard/3.jpg");
        } 
        catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } 
    
        Bitmap bitmapOrg1 = BitmapFactory.decodeStream(in1);
        ByteArrayOutputStream bao1 = new ByteArrayOutputStream();
        bitmapOrg1.compress(Bitmap.CompressFormat.JPEG, 90, bao1);
        byte [] imagearray1 = bao1.toByteArray();
        String ba1=Base64.encode(imagearray1);
    
        Bitmap bitmapOrg2 = BitmapFactory.decodeStream(in2);
        ByteArrayOutputStream bao2 = new ByteArrayOutputStream();
        bitmapOrg2.compress(Bitmap.CompressFormat.JPEG, 90, bao2);
        byte [] imagearray2 = bao2.toByteArray();
        String ba2=Base64.encode(imagearray2);
    
        Bitmap bitmapOrg3 = BitmapFactory.decodeStream(in3);
        ByteArrayOutputStream bao3 = new ByteArrayOutputStream();
        bitmapOrg3.compress(Bitmap.CompressFormat.JPEG, 90, bao3);
        byte [] imagearray3 = bao3.toByteArray();
        String ba3=Base64.encode(imagearray3);
    
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
    
        nameValuePairs.add(new BasicNameValuePair("image1",ba1));
        nameValuePairs.add(new BasicNameValuePair("image2",ba2));
        nameValuePairs.add(new BasicNameValuePair("image3",ba3));
    
        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://helpdesk.cispl.com/upload_file.php");
            UrlEncodedFormEntity obj = new UrlEncodedFormEntity(nameValuePairs);
            obj.setChunked(true);
            httppost.setEntity(obj);
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            //is = entity.getContent();
            httpclient.getConnectionManager().shutdown(); 
        }
        catch(Exception e){
            //CommonFunctions.writeLOG(ctx.getClass().toString(), e.toString());
            //CommonFunctions.showToast(ctx, "Unable to post captured image file: " +
            //e.toString());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit lost right now, what I'm trying to do: build a 1.5
I have lost many hours trying to grab exclusively the mouse in my application
I'm a bit lost with UTF-8 right now. I'm looking for a precise definition
Right now, I have a query that gets me 3 columns. SELECT a.studentID, a.classdetailID,
Right now I'm trying to tackle the problem of dealing with data either a)
i've been reading a lot and have been trying to get this done for
I have lost my private key for iPhone Distribution Certificate during an OS upgrade.
I'm trying to create a scrollable layout in Android. Even using developers.android.com, though, I
I'm trying to build something (ultimately a gem but for now an application) that
I'm trying to merge some data but beyond the basics I get a bit

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.