I'm making a sending file function of a chatroom. The language I'm using is nodejs (socket.io) and js.
The way I work it out is to
use javacript
fileReaderto read a file in chrunks asArrayBuffer, and transfer the pieces to server, server collects the data until all data is collected.Sever send
ArrayBufferback to the other clients.On the clientside, convert
ArrayBuffertobase64String, and add prefix depends on the MIME type such asdata:application/pdf;base64,.Insert this
base64Stringto a<a href='{thisBase64String}' download></a>.
Currently, it only works on those pdf files whose size are less than 2MB, the download attribute doesn't work on fileSize over 10MB.
My guess is the size of href too long causing the problem, any idea to fix this problem?
I know probably I can use fs.write to print out the uploaded file first, then link to the directory. But since it is a chatroom, I wish I can make everything on the air. There is no need spending time to maintain the server, isn't it?