上传带有进度条的图像android

时间:2019-06-13 13:17:32

标签: android retrofit

我要上传进度this之类的图片 它工作正常,但我想从呼叫中获取响应,他在服务内部使用了改造呼叫来上载,但响应仅是进度的两倍 我想回应我的json(json回应)

 @Override
protected void onHandleWork(@NonNull Intent intent) {
    Log.d(TAG, "onHandleWork: ");
    /**
     * Download/Upload of file
     * The system or framework is already holding a wake lock for us at this point
     */

    // get file file here
    mFilePath = intent.getStringExtra("mFilePath");
    if (mFilePath == null) {
        Log.e(TAG, "onHandleWork: Invalid file URI");
        return;
    }
    apiService = RetrofitInstance.getApiService();
    Flowable<Double> fileObservable = Flowable.create(new FlowableOnSubscribe<Double>() {
        @Override
        public void subscribe(FlowableEmitter<Double> emitter) throws Exception {
            apiService.onFileUpload(FileUploadService.this.createRequestBodyFromText("info@androidwave.com"), FileUploadService.this.createMultipartBody(mFilePath, emitter)).blockingGet();
            emitter.onComplete();
        }
    }, BackpressureStrategy.LATEST);

    mDisposable = fileObservable.subscribeOn(Schedulers.computation())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<Double>() {
                @Override
                public void accept(Double progress) throws Exception {
                    // call onProgress()
                    FileUploadService.this.onProgress(progress);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    // call onErrors() if error occurred during file upload
                    FileUploadService.this.onErrors(throwable);
                }
            }, new Action() {
                @Override
                public void run() throws Exception {
                    // call onSuccess() while file upload successful
                    FileUploadService.this.onSuccess();
                }
            });
}

0 个答案:

没有答案