修复无法导入大文件问题
This commit is contained in:
parent
ba1c2ccc98
commit
c45870eff5
|
|
@ -18,10 +18,15 @@ import java.io.InputStream;
|
|||
@Component
|
||||
public class DefaultImportExportService implements ImportExportService {
|
||||
|
||||
private final WebClient.Builder builder;
|
||||
|
||||
public DefaultImportExportService(WebClient.Builder builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public <T> Flux<RowResult<T>> doImport(Class<T> clazz, String fileUrl) {
|
||||
return getInputStream(fileUrl)
|
||||
.flatMapMany(inputStream -> ExcelReadDataListener.of(inputStream, clazz));
|
||||
.flatMapMany(inputStream -> ExcelReadDataListener.of(inputStream, clazz));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -31,16 +36,17 @@ public class DefaultImportExportService implements ImportExportService {
|
|||
|
||||
public Mono<InputStream> getInputStream(String fileUrl) {
|
||||
|
||||
return Mono.defer(()->{
|
||||
return Mono.defer(() -> {
|
||||
if (fileUrl.startsWith("http")) {
|
||||
return WebClient.create().get()
|
||||
return builder.build()
|
||||
.get()
|
||||
.uri(fileUrl)
|
||||
.accept(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.exchange()
|
||||
.flatMap(clientResponse -> clientResponse.bodyToMono(Resource.class))
|
||||
.flatMap(resource -> Mono.fromCallable(resource::getInputStream));
|
||||
} else {
|
||||
return Mono.fromCallable(()->new FileInputStream(fileUrl));
|
||||
return Mono.fromCallable(() -> new FileInputStream(fileUrl));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue