简体   繁体   中英

How to upload image to php server from Android App?

I am developing an android app. I want to upload an image to php server. The problem is that, the image on server side which gets uploaded is blank.

My android app code is:

    myBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);

    byte[] byteArray;
    byteArray = byteArrayOutputStream.toByteArray();

    String ConvertImage;
    ConvertImage = Base64.encodeToString(byteArray, Base64.DEFAULT);

ConvertImage is sent to server using GET Query "url?image=ConvertImage"

On Server Side, php script is:

    $image = $_GET['image'];

    $img = base64_decode($image);
    $path = "Images/new1.png";

    file_put_contents($path, $img);

After running the php script, the file gets created but i do not see the image.

How to solve this?

Try using smaller Images, if it gets uploaded than the problem is with the image size. Also I would suggest you to post images using Multipart method rather than converting them to string and passing in url. Of course only if you have access to the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM