
hope.kola.contract.api.MultipartFile Maven / Gradle / Ivy
package hope.kola.contract.api;
/**
* design according to the {@code restassured} logic
*
* {@link io.restassured.builder.MultiPartSpecBuilder} {@link
* io.restassured.config.MultiPartConfig}
*/
public class MultipartFile implements HeaderTrait {
protected String url;
protected String content;
protected String mimeType;
protected String charset;
protected String fileName;
/** default is file */
protected String controlName;
/**
* Specify the file name of this multipart. Note that this is only applicable for input streams,
* byte arrays and files and not string content.
*
* @param fileName The file name to use.
* @return An instance of MultipleFile
*/
public MultipartFile fileName(String fileName) {
this.fileName = fileName;
return this;
}
public String getFileName() {
return fileName;
}
public String getUrl() {
return url;
}
/**
* Upload file from class path resource
*
* @param path the path in the class path
* @return SELF
*/
public MultipartFile fromClasspath(final String path) {
this.url = "classpath:" + path;
return this;
}
/**
* Upload file from the file system resource
*
* @param path the path in the file system
* @return SELF
*/
public MultipartFile fromFile(final String path) {
this.url = "file:" + path;
return this;
}
/**
* Self-control protocol to upload the file
*
* @param url should follow the {@link java.net.URL} standard
* @return SELF
*/
public MultipartFile url(String url) {
this.url = url;
return this;
}
public String getContent() {
return content;
}
/**
* This is raw content, must be a stream, otherwise pass through the {@link #url} reference
*
* @param content the raw content of this file
* @return self
*/
public MultipartFile content(String content) {
this.content = content;
return this;
}
public String getMimeType() {
return mimeType;
}
/**
* Specify the mime-type for this multipart.
*
* @param mimeType The mime-type
*/
public MultipartFile mimeType(String mimeType) {
this.mimeType = mimeType;
return this;
}
public String getControlName() {
return controlName;
}
/**
* Specify the control name of this multipart.
*
* @param controlName The control name to use. Default is file
.
*/
public MultipartFile controlName(String controlName) {
this.controlName = controlName;
return this;
}
public String getCharset() {
return charset;
}
/**
* Specify the charset for this charset.
*
* @param charset The charset to use
*/
public MultipartFile charset(String charset) {
this.charset = charset;
return this;
}
}