|
@@ -11,13 +11,10 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
import org.springframework.core.io.ByteArrayResource;
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
|
-import org.springframework.web.reactive.function.BodyInserters;
|
|
|
|
|
-import org.springframework.web.reactive.function.client.WebClient;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
|
|
|
@@ -82,7 +79,7 @@ public class TKHttpClient {
|
|
|
|
|
|
|
|
formData.add("file", new FileSystemResource(file));
|
|
formData.add("file", new FileSystemResource(file));
|
|
|
|
|
|
|
|
- sendRequest(url, formData);
|
|
|
|
|
|
|
+ requestComponent.upload(url, formData);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -109,25 +106,6 @@ public class TKHttpClient {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- sendRequest(url, formData);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 上传文件请求
|
|
|
|
|
- *
|
|
|
|
|
- * @param url
|
|
|
|
|
- * @param formData
|
|
|
|
|
- */
|
|
|
|
|
- private void sendRequest(String url, MultiValueMap<String, Object> formData) {
|
|
|
|
|
- WebClient.create()
|
|
|
|
|
- .post()
|
|
|
|
|
- .uri(url)
|
|
|
|
|
- .contentType(MediaType.MULTIPART_FORM_DATA)
|
|
|
|
|
- .body(BodyInserters.fromMultipartData(formData))
|
|
|
|
|
- .retrieve()
|
|
|
|
|
- .bodyToMono(String.class)
|
|
|
|
|
- .doOnSuccess(response -> System.out.println("上传成功: " + response))
|
|
|
|
|
- .doOnError(e -> System.err.println("上传失败: " + e.getMessage()))
|
|
|
|
|
- .block();
|
|
|
|
|
|
|
+ requestComponent.upload(url, formData);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|