Skip to content

Error uploading file using Rsocket #1108

Open
@sdack-cloud

Description

@sdack-cloud

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions