New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Add support for sending large files (up to 2GB) #2368
base: main
Are you sure you want to change the base?
Conversation
Break the file down into 50MB chunks and send via batches, creating a string object for each chunk Afterwards decode each chunk into one bing string Todo: I am overriding the entire attachment into a new MessageMedia object. Overriding just the data field was not yielding results (it stayed the original big string) work is based out of: pedroslopez/whatsapp-web.js@main...matricce:whatsapp-web.js:fix/sendBigFiles
Correctly assign mimetype and filesize values
In JS we don't use var anymore (only for very specific cases). Instead of var, try use const for unmodified variables or let for variables that will have modifications. |
I've commited the changes, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to improve the code a little
Change from multiple variables of 50MBs each into one variable that gets appended by 50MB chunks See: https://github.com/pedroslopez/whatsapp-web.js/pull/2368/files/c452fe86bb0c5ff3c16863ae77e9e76ac8b66010
Please fix ESLint |
Fix commited! |
Please fix ESLint |
Fix commited (2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
does it work? |
Fix waveform on downloaded audio files
I don't know how to properly make staggered PRs (a PR that depends on another), but i added a small commit to fix audio waveform on downloaded voice files, this is unrelated to the main PR per say but its a very small change enabled by the new filesize field and getUploadLimits (added by this PR) as long as the media file is audio, opus codec, and its size is less than getUploadLimits (audio), waweb will send it as a voice memo, even though mediaData.type is not ptt This is useful so developers dont need to add media checks (and different message send/reply codes for each type of media) tagging @alechkos as he is the creator of the waveform feature |
it's not me, i just brought it from another lib |
npm install git+https://github.com/opssemnik/whatsapp-web.js#patch-1 i used this one but its not working for me not showing any error |
@PurpShell @alechkos can you help here, please? |
Currently the library breaks at +-50mb because of puppeteer's evaluate function, we hit node's string limit at 10x the current limit Locally, for files larger than that, i changed MessageMedia's data to be an array (and the underlying code to support that), however, since node's string limitation has changed in newer versions, i didnt include it in here |
I tried to send media about 380MB and its not work. |
Maybe we have to look for another way to send large files |
The fact that we are unsure of: what is exactly the limit of size, the conditions of failure, and the failing behaviour; is for me a real issue of stability. IMHO this would be great to identify a safe limit of size where the upload is stable; and trigger a (bypassable) exception if the file is bigger. |
I tried this code. It won't send. You need to update the code to the latest version and check it again |
PR Details
Use an additional evaluate function to setup a browser variable,
Break the file down into 50MB chunks and append to the browser with a loop of puppeteer evaluates
During sendMessage event, inside the browser, override the attachment's data with the variable previously created
work is based out of:
main...matricce:whatsapp-web.js:fix/sendBigFiles
Updated patch is from @shirser121:
https://github.com/pedroslopez/whatsapp-web.js/pull/2368/files/c452fe86bb0c5ff3c16863ae77e9e76ac8b66010
Description
Changes sendMessage in Client.js
it does not affect messages without media, or messages whose media is below 50 Megabytes
Create client objects (chunks) of 50MB parts of the original file contents.
Create metadata chunk to save the amount of data chunks
Afterwards, initiate sendMessage on the client, using a dummy MessageMedia object, which is overwritten inside the browser with the chunks sent previously
Related Issues
Fixes #2117
Fixes #1771
Fixes #1951
Fixes #1925
Motivation and Context
Currently the lib only allows <80MB files, which was fine, however, whatsapp web added support for 2GB files (2097152000 bytes)
How Has This Been Tested
npm install git+https://github.com/opssemnik/whatsapp-web.js#patch-1
Sending / Replying messages without attachments has been tested
Sending / replying messages with media (sticker, non sticker, voice and documents) < 50MB
Sending / replying messages with media (sticker, non sticker, voice and documents) > 50MB < 1GB
Types of changes
Checklist