0

I want upload an image file to my PHP webservice. I made a few requestIDs for my webservice but i dont know how to send the correct requestID to my PHP service.

Image upload is requestID 7. How can I add the requestID or what do I need to change to make it work?

Android code

    public void triggerImageUpload() {
        makeHTTPCall();
    }

    // Make HTTP call to upload Image to webservice.
    public void makeHTTPCall() {

        prgDialog.setMessage("uploading....");
        AsyncHttpClient client = new AsyncHttpClient();
         //Change link here. client

                client.post("#URL",
                params, new AsyncHttpResponseHandler() {

                    // When the response returned by REST has Http
                    // response code '200'
                    @Override
                    public void onSuccess(String response) {
                        // Hide Progress Dialog
                        prgDialog.hide();
                        Toast.makeText(getApplicationContext(), "Done.",
                                Toast.LENGTH_LONG).show();

                        Intent myIntent = new Intent(Foto1.this, Foto2.class);
                         Foto1.this.startActivity(myIntent);
                        }

PHP Code

if (isset($_POST['requestID'])) {
    $requestID = $_REQUEST['requestID'];
    if ($requestID = 1) {
        //empty
    }
    if ($requestID = 7) {
        // Get image string posted from Android App
        $requestID = $_REQUEST['requestID'];
        $base = $_REQUEST['image'];
        // Get file name posted from Android App
        $filename = $_REQUEST['filename'];
        // Decode Image
        $binary = base64_decode($base);
        header('Content-Type: bitmap; charset=utf-8');
        // Images will be saved under 'uploads' folder
        $file = fopen('uploads/'.$filename, 'wb');
        // Create File
        fwrite($file, $binary);
        fclose($file);
        echo 'Image upload complete, Please check your php file directory';
    }
5
  • how you are uploading image on server? Commented Jan 9, 2015 at 11:52
  • i pick a image from the gallery, convert it with base64 to a string. Put the string in a RequestParm and upload it. with the code in my post Commented Jan 9, 2015 at 12:10
  • maybe this could help stackoverflow.com/questions/23921356/… Commented Jan 9, 2015 at 12:44
  • @geekido nope, its working without requestIDs but i want to use it with requestID`s Commented Jan 9, 2015 at 12:47
  • I would try upLoadServerUri = "mywebsite.com/database/PDO/uploadFile.php?id="+requestID; and catch file with post, catch id with get Commented Jan 9, 2015 at 14:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.