Refactor multipart upload
This commit is contained in:
parent
744799630f
commit
1a54133472
@ -1,10 +1,12 @@
|
|||||||
package com.baeldung.functional;
|
package com.baeldung.functional;
|
||||||
|
|
||||||
|
import org.springframework.core.io.buffer.DataBuffer;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import static org.springframework.web.reactive.function.BodyExtractors.toDataBuffers;
|
import static org.springframework.web.reactive.function.BodyExtractors.toDataBuffers;
|
||||||
@ -28,13 +30,15 @@ public class FormHandler {
|
|||||||
return request
|
return request
|
||||||
.body(toDataBuffers())
|
.body(toDataBuffers())
|
||||||
.collectList()
|
.collectList()
|
||||||
.flatMap(dataBuffers -> {
|
.flatMap(dataBuffers -> ok()
|
||||||
AtomicLong atomicLong = new AtomicLong(0);
|
.body(fromObject(extractData(dataBuffers).toString())));
|
||||||
dataBuffers.forEach(d -> atomicLong.addAndGet(d
|
}
|
||||||
.asByteBuffer()
|
|
||||||
.array().length));
|
|
||||||
|
|
||||||
return ok().body(fromObject(atomicLong.toString()));
|
private AtomicLong extractData(List<DataBuffer> dataBuffers) {
|
||||||
});
|
AtomicLong atomicLong = new AtomicLong(0);
|
||||||
|
dataBuffers.forEach(d -> atomicLong.addAndGet(d
|
||||||
|
.asByteBuffer()
|
||||||
|
.array().length));
|
||||||
|
return atomicLong;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user