use of io.micronaut.http.multipart.CompletedPart in project micronaut-core by micronaut-projects.
the class UploadController method go.
@Post(value = "/receive-multipart-body", consumes = MediaType.MULTIPART_FORM_DATA, produces = MediaType.TEXT_PLAIN)
@SingleResult
public Publisher<String> go(@Body MultipartBody multipartBody) {
return Mono.create(emitter -> {
multipartBody.subscribe(new Subscriber<CompletedPart>() {
private Subscription s;
List<String> datas = new ArrayList<>();
@Override
public void onSubscribe(Subscription s) {
this.s = s;
s.request(1);
}
@Override
public void onNext(CompletedPart data) {
try {
datas.add(new String(data.getBytes(), StandardCharsets.UTF_8));
s.request(1);
} catch (IOException e) {
s.cancel();
emitter.error(e);
}
}
@Override
public void onError(Throwable t) {
emitter.error(t);
}
@Override
public void onComplete() {
emitter.success(String.join("|", datas));
}
});
});
}
use of io.micronaut.http.multipart.CompletedPart in project micronaut-core by micronaut-projects.
the class UploadController method multipartBodyWithPrincipal.
@Post(value = "/receive-multipart-body-principal", consumes = MediaType.MULTIPART_FORM_DATA, produces = MediaType.TEXT_PLAIN)
@SingleResult
public Publisher<String> multipartBodyWithPrincipal(Principal principal, @Body MultipartBody multipartBody) {
return Mono.create(emitter -> {
multipartBody.subscribe(new Subscriber<CompletedPart>() {
private Subscription s;
List<String> datas = new ArrayList<>();
@Override
public void onSubscribe(Subscription s) {
this.s = s;
s.request(1);
}
@Override
public void onNext(CompletedPart data) {
try {
datas.add(new String(data.getBytes(), StandardCharsets.UTF_8));
s.request(1);
} catch (IOException e) {
s.cancel();
emitter.error(e);
}
}
@Override
public void onError(Throwable t) {
emitter.error(t);
}
@Override
public void onComplete() {
emitter.success(String.join("|", datas));
}
});
});
}
use of io.micronaut.http.multipart.CompletedPart in project micronaut-core by micronaut-projects.
the class UploadController method publisherCompletedPart.
@Post(value = "/publisher-completedpart", consumes = MediaType.MULTIPART_FORM_DATA, produces = MediaType.TEXT_PLAIN)
@SingleResult
public Publisher<String> publisherCompletedPart(Publisher<CompletedPart> recipients) {
return Mono.create(emitter -> {
recipients.subscribe(new Subscriber<CompletedPart>() {
private Subscription s;
List<String> datas = new ArrayList<>();
@Override
public void onSubscribe(Subscription s) {
this.s = s;
s.request(1);
}
@Override
public void onNext(CompletedPart data) {
try {
datas.add(new String(data.getBytes(), StandardCharsets.UTF_8));
s.request(1);
} catch (IOException e) {
s.cancel();
emitter.error(e);
}
}
@Override
public void onError(Throwable t) {
emitter.error(t);
}
@Override
public void onComplete() {
emitter.success(String.join("|", datas));
}
});
});
}
Aggregations