retrofit2.0post图片上传到底如何写?

最近要上传头像url大概是htttp://loaclhost:8080/uploadaction?user_id=1&user_pic=
后面跟上传的图片,实在是不会用retrofit2.0post,能给个合适的demo么,网上的例子都都不
好用,只把user_id字段传上去了,user_pic后台获取不到.求大神解答

刚简单总结了一下,后续完善,实战可行,希望能帮助到你,见博客
http://blog.csdn.net/itjianghuxiaoxiong/article/details/52135748

http://blog.csdn.net/jdsjlzx/article/details/51511413

private void uploadFile(Uri fileUri) {

FileUploadService service =
ServiceGenerator.createService(FileUploadService.class);

File file = FileUtils.getFile(this, fileUri);

RequestBody requestFile =
        RequestBody.create(MediaType.parse("multipart/form-data"), file);

MultipartBody.Part body =
        MultipartBody.Part.createFormData("picture", file.getName(), requestFile);

String user_id = "1";
RequestBody user_id =
        RequestBody.create(
                MediaType.parse("multipart/form-data"), user_id);

Call<ResponseBody> call = service.upload(user_id, body);
call.enqueue(new Callback<ResponseBody>() {
    @Override
    public void onResponse(Call<ResponseBody> call,
                           Response<ResponseBody> response) {
        Log.v("Upload", "success");
    }

    @Override
    public void onFailure(Call<ResponseBody> call, Throwable t) {
        Log.e("Upload error:", t.getMessage());
    }
});

}

MultipartBody.Part body =
MultipartBody.Part.createFormData("picture", file.getName(), requestFile); 这个picture是固定的么,我之前看网上有写file得有些image*的好多,
都不好用,礼拜天服务器关了,我先问问

Bitmap 转 File,网上有很多,然后你可以看看这个 http://blog.csdn.net/lmj623565791/article/details/51304204 ,这个里面有单文件,多文件上传,就是这样了,我给你看下我的单文件上传吧
public interface IPublishFileLiveDynamic {

    @Multipart
    @POST("live_posts_add")
    Observable<BaseData> postFileLiveDynamic(
            @Part MultipartBody.Part file,
            @Part("live_id") String live_id,
            @Part("options") String options,
            @Part("kind") String kind,
            @Part("type") String type,
            @Part("token") String token,
            @Part("timestamp") String timestamp,
            @Part("content") String content,
            @Part("money") String money);

}

File file = new File(Environment.getExternalStorageDirectory(), "icon.png");
RequestBody photoRequestBody = RequestBody.create(MediaType.parse("image/png"), file);
MultipartBody.Part photo = MultipartBody.Part.createFormData("photos", "icon.png", photoRequestBody);


http://www.jb51.net/article/80374.htm