Skip to content
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

Failed to load resource on sendImage #2961

Open
1 task done
crescent1 opened this issue Nov 25, 2022 · 27 comments
Open
1 task done

Failed to load resource on sendImage #2961

crescent1 opened this issue Nov 25, 2022 · 27 comments

Comments

@crescent1
Copy link

crescent1 commented Nov 25, 2022

Are you using the latest version of the library?

  • I have checked and am using the latest version of the library.

What type of session are you experiencing this issue on?

Multi-device and I have set multiDevice to true in my config OR am using the --multi-device flag

What type of host account are you experiencing this issue on?

Personal account (normal)

Mode

My own code

Current Behavior

image failed to send (work fine on local development)

Expected Behavior

image sent successfully

Steps To Reproduce

client.sendImage( [email protected], https://drive.google.com/uc?id=19EXFscynB351dXfdPAL_PadPP0PeoH2R&export=download, basket.jpg, basket.jpg, null, false, false, false, false, false );

create() code OR full CLI command + CONFIG

create({
        sessionId: phone,
        useChrome: true,
        headless: true,
        authTimeout: 0, //set to 0 to wait forever for connection to phone
        qrTimeout: 0, //set to 0 to wait forever for a qr scan
        qrLogSkip: true,
        autoRefresh: true,
        restartOnCrash: start,
        sessionDataPath: './session',
        deleteSessionDataOnLogout: true,
        disableSpins: true,
        multiDevice: true,
        killClientOnLogout: true,
        logging: [
          {
            type: 'file',
            options: {
              filename: './logs/application-%DATE%.log',
            },
          },
        ]
      });

DEBUG INFO

{
  "WA_VERSION": "2.2245.9",
  "WA_AUTOMATE_VERSION": "4.51.1",
  "BROWSER_VERSION": "HeadlessChrome/107.0.5304.110",
  "START_TS": 1669358189291,
  "RAM_INFO": "Total: 2.07 GB | Free: 1.51 GB",
  "PPTR_VERSION": "15.0.0",
  "LATEST_VERSION": true,
  "CLI": false,
  "PATCH_HASH": "f69bc",
  "LAUNCH_TIME_MS": 42927,
  "ACC_TYPE": "PERSONAL",
  "chats": 106,
  "messages": 147,
  "contacts": 549,
  "isMd": true,
  "INSTANCE_ID": "cae36582-fe22-4eed-9c0e-82e61c77dc91"
}

Environment

- OS: Linux 5.15
- Node: 16.17.1
- npm: 8.19.3

Screenshots/Logs

info: Saved temporary file to /tmp/1m6a0qvwei.basket.jpg.jpeg {"timestamp":"2022-11-25T07:00:14.239Z"}
info: IN 0604e  {"_args":{"caption":"basket.jpg","file":"dn2isadk0","filename":"basket.jpg","hideTags":false,"ptt":false,"quotedMsgId":null,"to":"[email protected]","viewOnce":false,"waitForId":false,"withoutPreview":false},"_method":"sendImage","timestamp":"2022-11-25T07:00:14.258Z"}
info: Page Console: Failed to load resource: the server responded with a status of 404 () {"timestamp":"2022-11-25T07:00:14.594Z"}
info: IN 12e12  {"_args":{"content":"test","to":"[email protected]"},"_method":["sendSeen","sendMessage"],"timestamp":"2022-11-25T07:03:36.570Z"}
info: OUT 12e12: 131ms  {"res":"[email protected]_3EB0CD9E2A1890DD0656_out","timestamp":"2022-11-25T07:03:36.701Z"}
info: Saved temporary file to /tmp/221vlw8np6.IMG-20220722-WA0045.jpg.jpeg {"timestamp":"2022-11-25T07:03:55.287Z"}
info: IN 4f63a  {"_args":{"caption":"IMG-20220722-WA0045.jpg","file":"d1r3j4jak","filename":"IMG-20220722-WA0045.jpg","hideTags":false,"ptt":false,"quotedMsgId":null,"to":"[email protected]","viewOnce":false,"waitForId":false,"withoutPreview":false},"_method":"sendImage","timestamp":"2022-11-25T07:03:55.674Z"}
info: Page Console: Failed to load resource: the server responded with a status of 404 () {"timestamp":"2022-11-25T07:03:56.001Z"}
info: Saved temporary file to /tmp/1gmt8hadnp.IMG-20220722-WA0045.jpeg {"timestamp":"2022-11-25T07:08:39.070Z"}
info: IN df382  {"_args":{"caption":"IMG-20220722-WA0045","file":"dl20bynhv","filename":"IMG-20220722-WA0045","hideTags":false,"ptt":false,"quotedMsgId":null,"to":"[email protected]","viewOnce":false,"waitForId":false,"withoutPreview":false},"_method":"sendImage","timestamp":"2022-11-25T07:08:39.087Z"}
info: Page Console: Failed to load resource: the server responded with a status of 404 () {"timestamp":"2022-11-25T07:08:39.745Z"}

Anything else?

0|waapi  | Error: Evaluation failed: Error: MediaFileEmpty
0|waapi  |     at h.sendToChat (https://web.whatsapp.com/app.77ee8aa7a4c593101105.js:75:729330)
0|waapi  |     at pptr://__puppeteer_evaluation_script__:1:203630
0|waapi  |     at async window.<computed>.<computed> [as sendImage] (pptr://__puppeteer_evaluation_script__:1:200123)
0|waapi  |     at ExecutionContext._ExecutionContext_evaluate (/home/user/projects/waapi/node_modules/puppeteer/src/common/ExecutionContext.ts:306:13)
0|waapi  |     at runMicrotasks (<anonymous>)
0|waapi  |     at processTicksAndRejections (node:internal/process/task_queues:96:5)
0|waapi  |     at ExecutionContext.evaluate (/home/user/projects/waapi/node_modules/puppeteer/src/common/ExecutionContext.ts:150:12)
@luizgununes
Copy link

I'm having the same issue, "MediaFileEmpty", sending images or audio files. I am using an ARM CPU, and you?

@crescent1
Copy link
Author

on production server using DO-Premium-Intel.

@TramontaG
Copy link

TramontaG commented Nov 26, 2022

I'm also trying to send an image from an URL and it's throwing the following error on file node_modules/@open-wa/wa-automate/dist/utils/tools.js:28

function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 
                                                   ^
TypeError: mime_1.default.extension is not a function

I haven't tried yet downloading the image before sending it.

My code:

this.client.sendImage(
	message.from,
	url,
	'Youtube Thumbnail',
	caption
);
5|Gramonta-Bot  | ┌─────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
5|Gramonta-Bot  | │       (index)       │                                                                   Values                                                                   │
5|Gramonta-Bot  | ├─────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
5|Gramonta-Bot  | │     WA_VERSION      │                                                                 '2.2245.9'                                                                 │
5|Gramonta-Bot  | │       PAGE_UA       │ 'WhatsApp/2.2147.16 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36' │
5|Gramonta-Bot  | │ WA_AUTOMATE_VERSION │                                                                  '4.51.1'                                                                  │
5|Gramonta-Bot  | │   BROWSER_VERSION   │                                                      'HeadlessChrome/107.0.5304.121'                                                       │
5|Gramonta-Bot  | │         OS          │                                                                'Linux 5.15'                                                                │
5|Gramonta-Bot  | │      START_TS       │                                                               1669488816429                                                                │
5|Gramonta-Bot  | │      RAM_INFO       │                                                      'Total: 8.23 GB | Free: 2.75 GB'                                                      │
5|Gramonta-Bot  | │    PPTR_VERSION     │                                                                  '15.0.0'                                                                  │
5|Gramonta-Bot  | └─────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

@smashah
Copy link
Member

smashah commented Nov 27, 2022

@crescent1 the issue is clearly laid out in the logs:

Failed to load resource: the server responded with a status of 404 ()

The URL is returning 404 which is why the media file is empty. For some reason when I try your link it works fine here. Ensure the URL is valid before trying to send it as a file source.

@smashah
Copy link
Member

smashah commented Nov 27, 2022

@TramontaG what's your node version?

node --version
v18.12.1

@TramontaG
Copy link

TramontaG commented Nov 27, 2022

@smashah

I tried using v19.0.1 and v18.12.1, same error on both
The solution for me was to downgrade the library to 4.46.0

@smashah
Copy link
Member

smashah commented Nov 27, 2022

@TramontaG that's not a solution.

Please provide reproducible code and the file you are trying to send

@TramontaG
Copy link

TramontaG commented Nov 27, 2022

@smashah

The following exact code works on 4.46.0 but doesnt on 4.51.0

client.onAnyMessage(message => {
	try {
		if (message.body === "!dev_test"){
			client.sendImage(
				message.from,
				"https://www.belasmensagens.com.br/wp-content/uploads/2015/03/bom-dia-amigos-400x300.jpg",
				"testMessage",
				"sample caption",
				message.id,
			)
				return;
		}
	} catch (e) {
		console.warn(e);
	}
}

For version 4.51.0 i get the following error:

5|Gramonta-Bot  | /home/guigalleta/Projects/Gramonta-Bot/node_modules/@open-wa/wa-automate/dist/utils/tools.js:28
5|Gramonta-Bot  |         function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5|Gramonta-Bot  |                                                          ^
5|Gramonta-Bot  | TypeError: mime_1.default.extension is not a function
5|Gramonta-Bot  |     at /home/guigalleta/Projects/Gramonta-Bot/node_modules/@open-wa/wa-automate/dist/utils/tools.js:413:44
5|Gramonta-Bot  |     at Generator.next (<anonymous>)
5|Gramonta-Bot  |     at fulfilled (/home/guigalleta/Projects/Gramonta-Bot/node_modules/@open-wa/wa-automate/dist/utils/tools.js:28:58)
5|Gramonta-Bot  |     at processTicksAndRejections (node:internal/process/task_queues:95:5)
5|Gramonta-Bot  | error Command failed with exit code 1.

For version 4.46.0 I get no errors and the expected result:

image

@crescent1
Copy link
Author

@crescent1 the issue is clearly laid out in the logs:

Failed to load resource: the server responded with a status of 404 ()

The URL is returning 404 which is why the media file is empty. For some reason when I try your link it works fine here. Ensure the URL is valid before trying to send it as a file source.

Yeah, when i try on local development its work fine too, but give error after push to production, for now i am using 4.49.2 version and its working on both.

@TramontaG
Copy link

@crescent1 the issue is clearly laid out in the logs:

Failed to load resource: the server responded with a status of 404 ()

The URL is returning 404 which is why the media file is empty. For some reason when I try your link it works fine here. Ensure the URL is valid before trying to send it as a file source.

Yeah, when i try on local development its work fine too, but give error after push to production, for now i am using 4.49.2 version and its working on both.

Something regarding media delivery broke in this new version. I found that a module of mine that downloads songs from youtube was also crashing the bot after the update, even though i haven't changed a single line of code. Downgrading the lib made it work properly again.

smashah added a commit that referenced this issue Nov 29, 2022
@smashah
Copy link
Member

smashah commented Nov 29, 2022

@github-actions run

⚡ Release! ⚡
(async () => {
function exec(cmd) {
try {
	execSync(cmd, {stdio: 'inherit'})
}  catch (error) {
    console.log(`Status Code: ${error.status} with '${error.message}'`);
 }
}
//set the version type
process.env.VERS = "patch"

// Config
const gitUserEmail = "github-actions[bot]@users.noreply.github.com";
const gitUserName = "github-actions[bot]";

exec(`echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc`);
exec(`git config --global user.email "${gitUserEmail}"`);
exec(`git config --global user.name "${gitUserName}"`);
exec(`npm i -D`);
exec(`npm run release-ci $VERS`);

// types only package
exec('npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN')
exec(`npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN && npm run types:publish `);
exec(`git commit -a -m 'updated types-only package'`);
exec(`git push --force`);

//comment on the issue
var result = execSync(`npx auto-changelog -o ./tempchangelog.txt --commit-limit false --template ./compact-keepachangelog.hbs --stdout`).toString();

    await postComment(result);

//create changelog image
exec(`npm run release-image`);
exec(`git commit -a -m 'updated release-image'`);
exec(`git push --force`);
  })();

@smashah
Copy link
Member

smashah commented Nov 29, 2022

Changelog

🚀 Release 4.51.6 (2022-11-29)

@smashah
Copy link
Member

smashah commented Nov 29, 2022

@TramontaG the reason you're facing this issue is because you do not enter a valid filename for the image (should be testMessage.jpeg), the library then tries to correct your mistake by attempting to infer the mimetype - you might be using that package within your own code but an updated version which has a different API (extension became getExtension a few versions back).

Now I've updated the implementation of mime to the latest version. Please update and try again

@luizgununes
Copy link

Even with the update, i still having the error "MediaFileEmpty".

@smashah
Copy link
Member

smashah commented Dec 1, 2022

@luizgununes share some code with hardcoded values that gives u this error.

@luizgununes
Copy link

Here the code that gaves me the error. I've tried everything!

const { prefix } = require("../config.json");

exports.run = (bot, message) => {
bot.sendPtt(message.chat.id, "media/audios/oof.mp3");
bot.sendPtt(message.chat.id, "media/audios/oof.mp3", "oof");
bot.sendPtt(message.chat.id, "media/audios/oof.mp3", "oof.mp3");
bot.sendFile(message.chat.id, "media/audios/oof.mp3");
bot.sendFile(message.chat.id, "media/audios/oof.mp3", "oof");
bot.sendFile(message.chat.id, "media/audios/oof.mp3", "oof.mp3");
};

exports.help = {
name: "oof",
type: "audio",
aliases: ["ooof", "uf", "uff", "uuf"],
usage: ${prefix}oof,
};

@luizgununes
Copy link

Ah, I almost forgot. This error only happens in the production. Running on my computer works fine.

@smashah
Copy link
Member

smashah commented Dec 2, 2022

@luizgununes use relative file references.

media/.... should be ./media/......

@luizgununes
Copy link

Update:

exports.run = (bot, message) => {
  bot.sendPtt(message.chat.id, "../media/audios/oof.mp3");
  bot.sendPtt(message.chat.id, "../media/audios/oof.mp3", "oof");
  bot.sendPtt(message.chat.id, "../media/audios/oof.mp3", "oof.mp3");
  bot.sendFile(message.chat.id, "../media/audios/oof.mp3");
  bot.sendFile(message.chat.id, "../media/audios/oof.mp3", "oof");
  bot.sendFile(message.chat.id, "../media/audios/oof.mp3", "oof.mp3");
};

The error now is:
FILE_NOT_FOUND: Cannot find file. Make sure the file reference is relative, a valid URL or a valid DataURL: ../media/audios/oof.mp3

@smashah
Copy link
Member

smashah commented Dec 4, 2022

@luizgununes can you take a screenshot of your folder structure please. Clearly the library cannot find the file you are referring to. The library tries to check the file relative to the current working directory of the node process.

/my-project
	package.json
	/src
		index.ts
		/static
			/media
				audios
					oof.mp3

If you run npm run start from /my-project then the file reference will be from there instead of from ./src/index.ts.

so in order to get oof.mp3 you will need to use ./src/media/audios/oof.mp3

@luizgununes
Copy link

/my-project
             package.json
             /commands
                           oof.js
             index.js
             /media
                           /audios
                                        oof.mp3

@luizgununes
Copy link

Any news? I'm still stuck with this problem. Tried with another WhatsApp library and works fine, but I don't wanna migrate everything.

@smashah
Copy link
Member

smashah commented Jan 20, 2023

@luizgununes you can try using a full filepath instead of relative if you're still facing this problem. Clearly the library is unable to find the file.

If you hop in the discord (click the discord badge in the readme) then I can help you out there.

Closing as original issue is resolved.

@smashah smashah closed this as completed Jan 20, 2023
@eladcandroid
Copy link

@luizgununes
I'm facing the same issue - MediaFileEmpty, even with an absolute path, and only in production... any idea?

@Ali-dev-79
Copy link

@eladcandroid Did you found the solution?

@smashah smashah reopened this Sep 17, 2024
@smashah
Copy link
Member

smashah commented Sep 17, 2024

bump.

Can you both add the details of the issues you are having please.

@Ali-dev-79
Copy link

Ali-dev-79 commented Sep 17, 2024

Thank you for your help!

I'm trying to send media using the open-wa library. I've tried the following methods from the documentation so far:

sendImage
sendFile
sendFileFromUrl
However, I keep encountering the same error when I use these functions:

Error sending file: Error: Evaluation failed: Error: MediaFileEmpty at h (https://static.whatsapp.net/rsrc.php/v3/y1/r/BGsPbebOkB8.js?_nc_x=Ij3Wp8lg5Kz:70:191) at f.sendToChat (https://static.whatsapp.net/rsrc.php/v3i2ZR4/yA/l/rt/7I2P3Exo_xT.js?_nc_x=Ij3Wp8lg5Kz:1250:9360) at pptr://__puppeteer_evaluation_script__:1:191910 at async window.<computed>.<computed> [as sendImage] (pptr://__puppeteer_evaluation_script__:1:186038) at ExecutionContext._ExecutionContext_evaluate (/home/ahmad/workspace/wa-open/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:258:15) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async ExecutionContext.evaluate (/home/ahmad/workspace/wa-open/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:146:16)

I've successfully generated the base64 string and tested it elsewhere, where it worked perfectly. I also tried sending publicly accessible URLs, but I still encountered the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants