Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error uploading file using Rsocket #1108

Open
sdack-cloud opened this issue May 30, 2024 · 0 comments
Open

Error uploading file using Rsocket #1108

sdack-cloud opened this issue May 30, 2024 · 0 comments

Comments

@sdack-cloud
Copy link

sdack-cloud commented May 30, 2024

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
uploaded_file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant