要求將圖像連同純文本和明文數據一起上傳整數列表。 我使用@PartMap爲純數據改造 - 將Integer數組列表與圖像文件相結合
對於這裏的圖像部分是我的代碼
imageFile = new File(imagePath);
imageBody = RequestBody.create(MediaType.parse("image/*"), imageFile);
multipartImageBody = MultipartBody.Part.createFormData("file_name", imageFile.getName(), imageBody);
對於純數據
userIdBody = RequestBody.create(MediaType.parse("text/plain"), userId);
customerTypeBody = RequestBody.create(MediaType.parse("text/plain"), typeOfCustomer);
結合明文數據
HashMap<String, RequestBody> partMap = new HashMap<>();
partMap.put("userId", userIdBody);
partMap.put("customer_type", customerTypeBody);
請求
發生@POST<T> methodName(@PartMap Map<String, RequestBody> params, @Part MultipartBody.Part imageParam);
問題,如果我嘗試添加整數listarray爲Requestbody,將數據轉換成服務器無法解析,而我們應該從應用程序方面本身
我試圖
RequestBody.create(Mediatype,byte[])
發送正確的數據串
Requestbody有這種方法,它接受我們的數據作爲字節數組,我將數組轉換爲字節數組,但結果並不如預期。
我還有其他的可能嗎?
可以使用multipart上傳帶有文本數據的圖像 – Sony
我實際上有多個文本數據 –