Question

I have searched for this answer everywhere and I cant find it. Would love for someone to help me. I am trying to send strings and an image thru Multipart Entity to a server. The strings are getting to the database but the image is always saying "blob- 0 bytes" Below is my java and php code.

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            proPic.compress(CompressFormat.JPEG, 75, bos);
            byte[] data = bos.toByteArray();


            entity.addPart("tag", new StringBody("register"));
            entity.addPart("name", new StringBody(name));
            entity.addPart("email", new StringBody(email));
            entity.addPart("password", new StringBody(password));
            entity.addPart("image", new ByteArrayBody(data,"profileImage.jpg"));

and my server php

//request type is register new user
        $name = $_POST['name'];
        $profiePic = $_FILES['image']['name'];
        $email=$_POST['email'];
        $password=$_POST['password'];

Can someone please help? I am getting no errors just an empthy field

Was it helpful?

Solution

you can try use Ion a useful library https://github.com/koush/ion and this is a example to upload multipart data

Ion.with(getContext(), "https://koush.clockworkmod.com/test/echo")
.uploadProgressBar(uploadProgressBar)
.setMultipartParameter("goop", "noop")
.setMultipartFile("filename.zip", new File("/sdcard/filename.zip"))
.asJsonObject()
.setCallback(...)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top