我想制作一个可以从画布发送图像和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&lt;>((;。当我敬酒时,它显示[pointf(312.31,432.1212(,pointf(344.34,53.131(]。因此,我使如何通过改造将其发送。我需要您的帮助。
尝试像这样做
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);