2

I am using this library

api('io.socket:socket.io-client:1.0.0') {
        exclude group: 'org.json', module: 'json'
    }

I am sending files using the code below. It works for small files up to about 6MB. But for larger files, like 30MB, it attempts to upload for about 5 seconds but then the socket automatically "reconnects" without uploading.

        input = file.inputStream()
        byteArray = input.readBytes()

        val fileJson = JSONObject()
        fileJson.put("file", byteArray)
        socket.emit("media/upload", fileJson)

The server end seems fine, because it works from web to web.

Am I not doing it right?

Zoe
  • 27,060
  • 21
  • 118
  • 148
M. Usman Khan
  • 3,689
  • 1
  • 59
  • 69

1 Answers1

1

I had the same issue when dealing with files (100Mb), I then split the file into several small chunks/packets (1024 bytes), then make sure you don't create a new connection for every packet, you can then you can always write the packets to disk to get the file.

for splitting file you can reference How to break a file into pieces using Java?

It also has a sample on merging the file back

This is not the best solution but will get you going.

ishm
  • 21
  • 5