amitshekhariitbhu / Fast-Android-Networking

🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
https://outcomeschool.com
Apache License 2.0
5.69k stars 958 forks source link

FileName instead of complete Absolute path #523

Open voodo12345 opened 4 years ago

voodo12345 commented 4 years ago

I was using your library in my application and noticed that in multipart file upload, in filename complete path of file is coming in request for eg. in case of external storage something like /storage/0/emulated/filename.jpg and in case of internal storage /data/data/com.test.test/files/filename.jpg.

Ideally only the file name should come in request not the absolute path.

I think, it can be fixed by modifying in this particular code snippet, by extracting actual file name in fileName variable.

for (HashMap.Entry<String, List> entry : mMultiPartFileMap.entrySet()) { List fileBodies = entry.getValue(); for (MultipartFileBody fileBody : fileBodies) { String fileName = fileBody.file.getName(); MediaType mediaType; if (fileBody.contentType != null) { mediaType = MediaType.parse(fileBody.contentType); } else { mediaType = MediaType.parse(Utils.getMimeType(fileName)); } RequestBody requestBody = RequestBody.create(mediaType, fileBody.file); builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + entry.getKey() + "\"; filename=\"" + fileName + "\""), requestBody); } }