AnswerBun.com

io.socket restarts when sending large files from Android

Stack Overflow Asked by M. Usman Khan on September 2, 2020

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?

One Answer

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.

Answered by ishm on September 2, 2020

Add your own answers!

Related Questions

Replace duplicates items in array with different values

3  Asked on November 7, 2021 by mohamed-eshaftri

         

How to fix object “x” not found

2  Asked on November 7, 2021 by ronie-febriansah

 

link error when using random_device from boost

2  Asked on November 7, 2021 by dikiidog

     

Error: invalid input syntax for type integer

0  Asked on November 7, 2021 by hammad-ali

     

android studio : My app crashes immediately after start

5  Asked on November 7, 2021 by user13930404

   

Int + Str type python

1  Asked on November 7, 2021

     

Javascript Output is giving empty response

0  Asked on November 7, 2021 by manish-jha

     

Create many CSV Files based on Pandas df column value

2  Asked on November 7, 2021 by eithar

       

How to change radio button checked attribute

2  Asked on November 7, 2021 by white-death

       

Vue js/Javascript Objects.assign() not working

0  Asked on November 7, 2021 by madsongr

     

Problems with HTTP/2 on nginx for Windows?

0  Asked on November 7, 2021 by camaross

     

Error to start application after insert Entity Framework

1  Asked on November 7, 2021 by bircastri

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP