I've been doing this all day, writing a blog
private void Uploadmultifile () {
String ImageType = "Multipart/form-data";
File File = new file (imgurl); Imgurl as Picture position
Requestbody filebody = requestbody.create (Mediatype.parse ("image/jpg"), file);
Requestbody requestbody = new Multipartbody.builder ()
. SetType (Multipartbody.form)
. Addformdatapart ("File", "Head_image", Filebody)
. Addformdatapart ("imagetype", ImageType)
. build ();
Request Request = new Request.builder ()
. URL (URL)
. Post (Requestbody)
. build ();
Final OKHTTP3. Okhttpclient.builder Httpbuilder = new Okhttpclient.builder ();
Okhttpclient okhttpclient = Httpbuilder
. build ();
Okhttpclient.newcall (Request) Enqueue (new Callback () {
@Override
public void OnFailure (Request request, IOException e) {
}
@Override
public void Onresponse (Response Response) throws IOException {
String htmlstr = Response.body (). String ();
LOG.I ("result", htmlstr);
}
});
}
Android uses OKHTTH to upload images Multipart/form-data