Skip to content

Commit a9a5dbf

Browse files
committed
HttpTask 新增 addFilePara(String name, byte[] content, String fileName) 与 addFilePara(String name, InputStream stream, String fileName) 方法
1 parent 4b479e0 commit a9a5dbf

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

okhttps/src/main/java/com/ejlchina/okhttps/HttpTask.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,26 @@ public C addFilePara(String name, String type, byte[] content) {
559559
return addFilePara(name, type, name + DOT + type, content);
560560
}
561561

562+
/**
563+
* 添加文件参数(以 multipart/form-data 形式上传)
564+
* @param name 参数名
565+
* @param content 文件内容
566+
* @param fileName 文件名: 如 xxx.txt、xxx.png、xxx.doc 等
567+
* @return HttpTask 实例
568+
* @since v3.5.1
569+
*/
570+
public C addFilePara(String name, byte[] content, String fileName) {
571+
if (fileName != null) {
572+
int dotIdx = fileName.indexOf(DOT);
573+
if (dotIdx >= 0 && dotIdx < fileName.length() - 1) {
574+
String type = fileName.substring(dotIdx + 1);
575+
return addFilePara(name, type, fileName, content);
576+
}
577+
return addFilePara(name, null, fileName, content);
578+
}
579+
return (C) this;
580+
}
581+
562582
/**
563583
* 添加文件参数(以 multipart/form-data 形式上传)
564584
* @param name 参数名
@@ -589,6 +609,26 @@ public C addFilePara(String name, String type, InputStream stream) {
589609
return addFilePara(name, type, name + DOT + type, stream);
590610
}
591611

612+
/**
613+
* 添加文件参数(以 multipart/form-data 形式上传)
614+
* @param name 参数名
615+
* @param stream 文件输入流
616+
* @param fileName 文件名: 如 xxx.txt、xxx.png、xxx.doc 等
617+
* @return HttpTask 实例
618+
* @since v3.5.1
619+
*/
620+
public C addFilePara(String name, InputStream stream, String fileName) {
621+
if (fileName != null) {
622+
int dotIdx = fileName.indexOf(DOT);
623+
if (dotIdx >= 0 && dotIdx < fileName.length() - 1) {
624+
String type = fileName.substring(dotIdx + 1);
625+
return addFilePara(name, type, fileName, stream);
626+
}
627+
return addFilePara(name, null, fileName, stream);
628+
}
629+
return (C) this;
630+
}
631+
592632
/**
593633
* 添加文件参数(以 multipart/form-data 形式上传)
594634
* @param name 参数名

0 commit comments

Comments
 (0)