Browse Source

perfect uploading file method

yanyi 7 years ago
parent
commit
fba0663a4e
1 changed files with 1 additions and 1 deletions
  1. 1 1
      okhttp2/src/main/java/com/mylove/okhttp/ObservableRequest.java

+ 1 - 1
okhttp2/src/main/java/com/mylove/okhttp/ObservableRequest.java

@@ -342,10 +342,10 @@ class ObservableRequest {
                 .setType(MultipartBody.ALTERNATIVE);
         if (FormatUtil.isMapNotEmpty(oMap)) {
             for (Map.Entry<Object, Object> entry : oMap.entrySet()) {
-                File file = new File(entry.getValue().toString());
                 int indexOf = entry.getValue().toString().lastIndexOf("/");
                 int indexOf1 = entry.getValue().toString().lastIndexOf(".");
                 if (indexOf > 0 && indexOf1 > 0) {
+                    File file = new File(entry.getValue().toString());
                     RequestBody requestBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);
                     String fileName = entry.getKey().toString().substring(indexOf + 1, entry.getKey().toString().length());
                     builder.addFormDataPart(entry.getKey().toString(), fileName, requestBody);