http推送文件类型的文件的处理,没有中间的file内容

1、创建特殊的文件流的类

package com.newtouch.claimCA.http;
import org.springframework.core.io.InputStreamResource;
import java.io.InputStream;

public class CommonInputStreamResource extends InputStreamResource {
    private long length;
 
    public CommonInputStreamResource(InputStream inputStream) {
        super(inputStream);
    }
 
    public CommonInputStreamResource(InputStream inputStream, int length) {
        super(inputStream);
        this.length = length;
    }

    @Override
    public String getFilename() {
        return "temFile";
    }
 
    @Override
    public long contentLength() {
        return length == 0 ? 1 : length;
    }
}

接口的测试内容:

@RequestMapping(value = "/v1.0/test")
public String test(@RequestBody Map map) {

    String ss = "iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAABhKSURBVGhD3ZjnV1TZtsX5T+7r3CqZRhFRASWIKEEEFUUaEUUlShSQIMFAkpxzFrXFBCoGWgHJsaiiAhTR1DeM8cb7Ot/cB/HSXvTd9/V+mONwDlXn7N9Za821dumMav6O/xT9Z8EsqOfxTjn7Se9VWnxQz0n6QzP/6W9x/e0M/z+7IOmtWos3qn9+XhzfKWbwfnoWH5S8Rolrf9LM/MfvafgsDd6r1figUuO9UoV300q8U/FIif8v895L6lksaOYwr1mQJM7X0zwZ5Op30BELEvp3YMQD3vLm77goAfSB+kO7uHLULOLv2jf42+yy9Hlxr7fTM9JRnP91ZgELchWWpjUfn6fh/9UShID5BPUZzBK/K4AW1F+GWZXOKsSqvgQjiQsXIAJI6I14y3wryyqeq3ic5rmSIHzwh5klSe8JKe4p7v2PhfcS+LJyBm8UjIxqBn/V8HkEeauYJswKoJD4zJIkLRb5/UXl/LoAayXBrEZHpIDQO/H219PMorT4twz5+9klvNMu4e3soqT3c8sr5/yf+Iz0OQIKCTgBNTepkoDF3+JFrbxADf7gQgTUP2FWYEUUlxRcKIE+QX1FX4VZjcCqRASkRa5Z/CIjJeU1vzfHe2jlakkLrJ9F1s+inG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2lUNQWQsNIvS7OQn9tKXrrq/GsvgF3KupwytMfxnpW0CPQTyJ9ac/f0/q/pb4xssc3xrZSJohr3+mvSDjczyYuUv1uNHHG/wLRFI/gfREk3gAAAABJRU5ErkJggg==";
     InputStream inputStream = Base64Utils.baseToInputStream(ss);
    ReturnMsg bearerToken = callTokenUtil.getToken("", null, "client_credentials");
    String s = com.alibaba.fastjson.JSONObject.toJSONString(bearerToken);
    com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(s);
    com.alibaba.fastjson.JSONObject transfer = object.getJSONObject("dataTable").getJSONObject("value");
    TokenDTO tokenDTO = JSON.toJavaObject(transfer, TokenDTO.class);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    headers.set("Authorization", "bearer "+tokenDTO.getAccess_token());
    MultiValueMap params = new LinkedMultiValueMap<>();
    params.add("Picture1", new CommonInputStreamResource(inputStream));
    params.add("Picture2", new CommonInputStreamResource(inputStream));
    HttpEntity> httpEntity = new HttpEntity<>(params, headers);
    RestTemplate restTemplate1 = new RestTemplate();
    ResponseEntity response = restTemplate1.postForEntity("http://10.219.113.183:19918/msf-service-base/rest/DoFaceCompare", httpEntity, String.class);
    System.out.println(response);

    return "";
}

你可能感兴趣的:(http,java,spring)