4

I have integrated socket.io into my android application to make a chat application. Now I wants to upload and share files like images, mp3 or doc file etc. How do I upload a file with socket.io I cannot find any documentation for doing.

2 Answers 2

1

It is not a good practice. This may lead blocking heartbeat messages between client and server if upload progress is long.

You may upload file with http post and send download link to chat peer. By doing this, a new connection is established for uploading and never breaks socket.io session.

Sign up to request clarification or add additional context in comments.

Comments

-1

I believe it should be a good practice to do in Android, as it works pretty well on web JS for small files such as Images, PDFs, etc.

But ya sending the whole file in a single shot is not a good practice(theoretically there should be no problem in doing that using socket.io), but it's better if you can the fragment the file into smaller pieces (maybe 2^10 to 2^20 bytes), and send it in pieces, doing so will also allow you to know the percentage of file's data transferred.

I am not good with JAVA, but I hope you can find a way to do that fragmentation thing.

But there is no inbuilt resource available in socket.io to transfer files, but you won't have any problem in sending pure Buffer(including '\0' in it) if you can manage to create a JSON object in JAVA without involving strings. As '\0' inside Strings messes them up.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.