Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file name parameter in Multipart File Body #570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,14 @@ public RequestBody getMultiPartRequestBody() {
for (HashMap.Entry<String, List<MultipartFileBody>> entry : mMultiPartFileMap.entrySet()) {
List<MultipartFileBody> fileBodies = entry.getValue();
for (MultipartFileBody fileBody : fileBodies) {
String fileName = fileBody.file.getName();

String fileName = "";
if (fileBody.fileName == null || fileBody.fileName.trim().equals("")) {
fileName = fileBody.file.getName();
}else{
fileName = fileBody.fileName;
}

MediaType mediaType;
if (fileBody.contentType != null) {
mediaType = MediaType.parse(fileBody.contentType);
Expand Down Expand Up @@ -1845,6 +1852,12 @@ public T addMultipartFile(Map<String, File> multiPartFileMap, String contentType
return (T) this;
}

public T addMultipartFile(String key,String fileName, File file, String contentType) {
MultipartFileBody fileBody = new MultipartFileBody(file, contentType,fileName);
addMultipartFileWithKey(key, fileBody);
return (T) this;
}

public T addMultipartFileList(String key, List<File> files) {
return addMultipartFileList(key, files, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ public class MultipartFileBody {

public final File file;
public final String contentType;
public String fileName;

public MultipartFileBody(File file, String contentType) {
this.file = file;
this.contentType = contentType;
}

public MultipartFileBody(File file, String contentType, String fileName) {
this.file = file;
this.contentType = contentType;
this.fileName = fileName;
}

}
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Thu Apr 12 21:48:48 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip