Problem description: The third party wrote an interface for uploading files. The request method of this interface is Post request. The request parameters are all submitted in the form of form-data, which contains three parameters.
The first one: cookie (string type)
The second one: seqNo (string type)
Third: file (file type)
Solution: When using the traditional Spring Cloud Feign component to call the remote interface to implement file upload, an abnormal error sometimes occurs. Consider using the following two methods to upload files.
The first way : use RestTemplate to call
import org.springframework.core.io.InputStreamResource;
import java.io.InputStream;
public class CommonInputStreamResource extends InputStreamResource {
private long length;
private String fileName;
public CommonInputStreamResource(InputStream inputStream, long length, String fileName) {
super(inputStream);
this.length = length;
this.fileName = fileName;
}
/**
* 覆写父类方法
* 如果不重写这个方法,并且文件有一定大小,那么服务端会出现异常
* {@code The multi-part request contained parameter data (excluding