使用翻新中的多部分发送翻新中的图像和阵列

时间:2019-03-18 16:02:00

标签: android gson retrofit rx-java multipart

我正在尝试使用多部分发送图像和数组。我已经成功地使用多部分上传了图像,但是无法发送数组。

界面

  @Multipart
@retrofit2.http.POST("/" + POST_USER_STORIES)
Observable<JsonObject> uploadUserStory(@Part MultipartBody.Part storyData,
                                       @Nullable @Part("story[resource_type]") RequestBody resourceType,
                                       @Nullable @Part("story[mentionees]") RequestBody mentioneesType);

我正在发送图像,资源类型和数组

 RequestBody requestFile;

        requestFile = RequestBody.create(MediaType.parse("image/jpeg"), ImageUtil.getByteArrayFromUri(getApplicationContext(), uri));
        MultipartBody.Part photoData = MultipartBody.Part.createFormData("story[resource]", fileName, requestFile);
        RequestBody photoType = RequestBody.create(MediaType.parse("text/plain"), "image");
        RequestBody mentioneesyType = RequestBody.create(MediaType.parse("text/plain"), new Gson().toJson(list));


        ServerTask.getInstance().getServices()
                .uploadUserStory(photoData, photoType, mentioneesyType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(story -> {
                    DialogUtil.dismissAllDialog();
                    onUploadStorySuccess();
                }, err -> {
                    Log.d(TAG, "uploadUserStory: " + err.toString());
                    DialogUtil.dismissAllDialog();        
                });

和尝试发送的数组

ArrayList<Mentionees> list = new ArrayList<>();

Mentionees mentioneesUploadModel = new Mentionees();

            mentioneesUploadModel.setColorCode("#ff00ff");
            mentioneesUploadModel.setFont("regular");
            mentioneesUploadModel.setPosX((int) getWidthInPercentage(f.getX()));
            mentioneesUploadModel.setPosY((int) getHeightInPercentage(f.getY()));
            mentioneesUploadModel.setMentionableId(result.getId());
            mentioneesUploadModel.setMentionableType(result.getSearchableType());
            mentioneesUploadModel.setName(result.getContent());
            mentioneesUploadModel.setPhoto("");

            list.add(mentioneesUploadModel);

我的请求执行成功,但数组未发布

0 个答案:

没有答案