rsocket-java
rsocket-java copied to clipboard
Error uploading file using Rsocket
I use the Spring framework to implement data reception
Kotlin
@MessageMapping("/upload")
fun upload(@Payload fileData: ByteArray?): Mono<String> {
println("========= OK")
println("========= OK "+ fileData!!.size)
val uploadFile = File("/Users/Downloads/uploaded_file.png")
// return Mono.just("ok")
return Mono.just("ok").doOnSuccess {
try {
FileOutputStream(uploadFile).use { fos ->
fos.write(fileData!!)
}
} catch (e: IOException) {
e.printStackTrace()
}
}
}
I use srocket js to upload files
upload(file) {
let route = encodeRoute("/upload");
let compositeMetaData = encodeCompositeMetadata([
[WellKnownMimeType.MESSAGE_RSOCKET_ROUTING, route]
]);
const reader = new FileReader();
reader.onload = (event) => {
let result = event.target.result as ArrayBuffer;
console.log(result)
this.socket.requestResponse({data: Buffer.from(result), metadata: compositeMetaData}, {
onComplete(): void {
}, onError(error: Error): void {
console.error("Error", error);
}, onExtension(extendedType: number, content: Buffer | null | undefined, canBeIgnored: boolean): void {
}, onNext(payload: Payload, isComplete: boolean): void {
console.log("OK", isComplete);
console.log("payload", payload.data);
}
})
}
reader.readAsArrayBuffer(file);
}
Result:
When receiving 130KB, it is possible, but there is an error if it is greater than 130Kb
Please provide an example program to tell me what to do
This image only has a portion