service請求引數:
;請求過程:
核心部分
requestbodyrequestfile =全部**:requestbody.create(
mediatype.parse(
"multipart/form-data"
), file)
;multipartbody.
partbody =
multipartbody.
part.createformdata(
"attach_file"
,file.getname()
, requestfile)
;
finalstringmp4path =上面的**有缺陷!!!!!!!environment.getexternalstoragedirectory()
.getabsolutepath()
+ "/video.mp4"
;final longfilesize =
newfile(mp4path)
.length()
;retrofithelper.create()
"video.mp4", (
int) filesize)
.filter(
newpredicate<
response<
>>
() }
).flatmap(
newfunction<
response<
>,
observable
<
file>>
() }
).flatmap(
newfunction<
file,
observable
<
response<
uploadfilemodel>>>
() }
).compose(
rxtransformer.<
uploadfilemodel>handleresult(
this))
.subscribe(
newconsumer<
uploadfilemodel>
() },
newconsumer<
throwable>
() }})
;
上傳的引數 key,伺服器接受到的值會帶有引號,所以需要修改如下:
@post("/api/chunkupload/upload"
)observable
<
response<
uploadfilemodel>>
fileupload
(@body
requestbody params)
;
multipartbody.builderbuilder =
newmultipartbody.builder()
.settype(
multipartbody.
form);
builder.addformdatapart(
"key"
, key);
builder.addformdatapart(
"attach_file"
, file.getname()
,requestbody
.create(
mediatype.parse(
"multipart/octet-stream"
), file))
;returnretrofithelper.create()
.fileupload(builder.build())
;
RxJava基本使用2
map變換操作符 將傳送的資料按指定的函式去變化 例子 observable.create new observableonsubscribe map new function subscribe new consumer flatmap變換操作符 將傳送的事件分解成多個事件後發送回接收方 注意 f...
Retrofit2極簡教程
注 使用之前先依賴retrofit compile com.squareup.retrofit2 retrofit 2.1.0 compile com.squareup.retrofit2 converter gson 2.1.0 定義好介面後,先進行初始化,以下是 所有請求的方法最好寫在乙個介面中...
RxJava2原始碼解析
原始碼總結 observabel 通過create方法。將observableonsubscribe物件傳遞給自己。通過subscribe方法。建立 observableemitter發射器物件。發射器裡又封裝了observer。發射器又作為引數傳遞 給observableonsubscribe物件...