Skip to content

Commit fad9891

Browse files
committed
file://path
1 parent 2c8f6f9 commit fad9891

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/com/qiniu/io/IO.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,15 @@ public void onFailure(Exception ex) {
9494
*/
9595
public void putFile(Context mContext, String key, Uri uri, PutExtra extra, final JSONObjectRet ret) {
9696
if (!uri.toString().startsWith("file")) uri = convertFileUri(mContext, uri);
97-
try {
98-
File file = new File(new URI(uri.toString()));
99-
if (file.exists()) {
100-
putAndClose(key, InputStreamAt.fromFile(file), extra, ret);
101-
return;
102-
}
103-
ret.onFailure(new Exception("file not exist: " + uri.toString()));
104-
} catch (URISyntaxException e) {
105-
e.printStackTrace();
106-
ret.onFailure(e);
97+
98+
File file = new File(uri.getEncodedPath());
99+
if (file.exists()) {
100+
putAndClose(key, InputStreamAt.fromFile(file), extra, ret);
101+
return;
107102
}
103+
ret.onFailure(new Exception("file not exist: " + uri.toString()));
108104
}
105+
109106
public void putFile(String key, File file, PutExtra extra, JSONObjectRet callback) {
110107
putAndClose(key, InputStreamAt.fromFile(file), extra, callback);
111108
}

src/com/qiniu/resumableio/ResumableIO.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,11 @@ public int putFile(String key, File file, PutExtra extra, final JSONObjectRet re
149149

150150
public int putFile(Context mContext, String key, Uri uri, PutExtra extra, final JSONObjectRet ret) {
151151
if (!uri.toString().startsWith("file")) uri = convertFileUri(mContext, uri);
152-
try {
153-
File file = new File(new URI(uri.toString()));
154-
if (file.exists()) return putAndClose(key, InputStreamAt.fromFile(file), extra, ret);
155-
ret.onFailure(new Exception("file not exist: " + uri.toString()));
156-
} catch (URISyntaxException e) {
157-
e.printStackTrace();
158-
ret.onFailure(e);
159-
}
152+
153+
File file = new File(uri.getEncodedPath());
154+
if (file.exists()) return putAndClose(key, InputStreamAt.fromFile(file), extra, ret);
155+
ret.onFailure(new Exception("file not exist: " + uri.toString()));
156+
160157
return -1;
161158
}
162159

0 commit comments

Comments
 (0)