如何在Android上发布带有翻新版的List <pointf>?

时间:2019-05-23 03:05:50

标签: android arraylist retrofit multipart

我想制作一个可以从画布发送图像和PointF的android应用。我已经成功发送了带有retorifit multipart的图像。我的下一个目标是发送列表。但是我很困惑如何发送?

这是发送图片的代码


final ProgressRequestBody fileBody = new ProgressRequestBody(uploadFile, this);
                final MultipartBody.Part body = MultipartBody.Part.createFormData("image", uploadFile.getName(), fileBody);

                new Thread(new Runnable() {
                    @Override
                    public void run() {

                        Observable<String> upload = apiService.uploadFile(body);

                        upload.subscribeOn(Schedulers.io())
                                .observeOn(AndroidSchedulers.mainThread())
                                .unsubscribeOn(Schedulers.io())
                                .subscribe(new Observer<String>() {
                                    @Override
                                    public void onSubscribe(Disposable d) {

                                    }

                                    @Override
                                    public void onNext(String s) {

                                        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);

                                        Glide.with(PolygonActivity.this)
                                                .load(s)
                                                .apply(RequestOptions.skipMemoryCacheOf(true))
                                                .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
                                                .into(sourceImageView);
                                    }

                                    @Override
                                    public void onError(Throwable t) {
                                        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
                                        Toast.makeText(PolygonActivity.this, "error response: " + t.getMessage(), Toast.LENGTH_SHORT).show();
                                    }

                                    @Override
                                    public void onComplete() {

                                    }
                                });

                    }}).start();

这是我的ApiService


@Multipart
    @POST("api/upload")
    Observable<String> uploadFile(@Part MultipartBody.Part file);

我想发送私有列表pointFS = new ArrayList <>(); 。当我敬酒pointFS时,显示[PointF(312.31,432.1212),PointF(344.34,53.131)]。所以我很困惑如何通过改造发送它。我需要你的帮助。

1 个答案:

答案 0 :(得分:0)

尝试这样做

    Gson gson = new Gson(); 
    String pointFListString= gson.toJson(pointFSArrayList);
RequestBody pointFList= RequestBody.create(MediaType.parse("multipart/form-data"), pointFListString);

    @Multipart
        @POST("api/upload")
        Observable<String> uploadFile(@Part MultipartBody.Part file,
                                      @Part("pointFArrayKey") RequestBody pointFList);