|
@@ -2,15 +2,16 @@ package com.benyanyi.okhttp.type;
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
|
-import com.benyanyi.okhttp.download.DownloadCall;
|
|
|
|
-import com.benyanyi.okhttp.download.DownloadConfig;
|
|
|
|
import com.benyanyi.okhttp.call.HttpCall;
|
|
import com.benyanyi.okhttp.call.HttpCall;
|
|
import com.benyanyi.okhttp.call.RequestConfig;
|
|
import com.benyanyi.okhttp.call.RequestConfig;
|
|
|
|
+import com.benyanyi.okhttp.download.DownloadCall;
|
|
|
|
+import com.benyanyi.okhttp.download.DownloadConfig;
|
|
import com.benyanyi.okhttp.util.FormatUtil;
|
|
import com.benyanyi.okhttp.util.FormatUtil;
|
|
import com.benyanyi.okhttp.util.OkHttpLog;
|
|
import com.benyanyi.okhttp.util.OkHttpLog;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
import okhttp3.FormBody;
|
|
import okhttp3.FormBody;
|
|
@@ -160,6 +161,50 @@ public class HttpRequest implements RequestType {
|
|
return send(true);
|
|
return send(true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public RequestConfig file(String... filePaths) {
|
|
|
|
+ MultipartBody.Builder builder = new MultipartBody.Builder()
|
|
|
|
+ .setType(MultipartBody.FORM);
|
|
|
|
+ if (filePaths != null && filePaths.length > 0) {
|
|
|
|
+ for (String str : filePaths) {
|
|
|
|
+ File file = new File(str);
|
|
|
|
+// int indexOf = entry.getValue().toString().indexOf("/");
|
|
|
|
+// RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);
|
|
|
|
+ RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
|
|
|
|
+// String fileName = entry.getKey().toString().substring(indexOf + 1);
|
|
|
|
+ builder.addFormDataPart("file", file.getName(), requestBody);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ MultipartBody multipartBody = builder.build();
|
|
|
|
+ request = new Request.Builder()
|
|
|
|
+ .url(url)
|
|
|
|
+ .post(multipartBody)
|
|
|
|
+ .build();
|
|
|
|
+ return send(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public RequestConfig file(List<String> filePaths) {
|
|
|
|
+ MultipartBody.Builder builder = new MultipartBody.Builder()
|
|
|
|
+ .setType(MultipartBody.FORM);
|
|
|
|
+ if (filePaths != null && filePaths.size() > 0) {
|
|
|
|
+ for (String str : filePaths) {
|
|
|
|
+ File file = new File(str);
|
|
|
|
+// int indexOf = entry.getValue().toString().indexOf("/");
|
|
|
|
+// RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);
|
|
|
|
+ RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
|
|
|
|
+// String fileName = entry.getKey().toString().substring(indexOf + 1);
|
|
|
|
+ builder.addFormDataPart("file", file.getName(), requestBody);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ MultipartBody multipartBody = builder.build();
|
|
|
|
+ request = new Request.Builder()
|
|
|
|
+ .url(url)
|
|
|
|
+ .post(multipartBody)
|
|
|
|
+ .build();
|
|
|
|
+ return send(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public DownloadConfig download() {
|
|
public DownloadConfig download() {
|
|
return new DownloadCall.Builder().setContext(context).setUrl(url).setCover(false).setSuffix("").builder();
|
|
return new DownloadCall.Builder().setContext(context).setUrl(url).setCover(false).setSuffix("").builder();
|