Envoyer une image dans la charge utile de notification
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
L'API FCM HTTP v1 et le composeur de notifications permettent d'envoyer des liens d'images dans la charge utile d'une notification à afficher, pour que les images soient téléchargées sur l'appareil après l'envoi.
La taille des images pour les notifications est limitée à 1 Mo. Elles sont également soumises aux restrictions liées à la prise en charge des images dans Android natif.
Créer la requête d'envoi
Dans votre requête d'envoi de notification, définissez l'option AndroidConfig suivante :
notification.image
contenant l'URL de l'image
L'exemple de requête d'envoi suivant envoie un titre de notification commun à toutes les plates-formes, mais il envoie également une image. Voici une approximation de l'effet visuel sur l'appareil d'un utilisateur :

Node.js
const topicName = 'industry-tech';
const message = {
notification: {
title: 'Sparky says hello!'
},
android: {
notification: {
imageUrl: 'https://foo.bar.pizza-monster.png'
}
},
apns: {
payload: {
aps: {
'mutable-content': 1
}
},
fcm_options: {
image: 'https://foo.bar.pizza-monster.png'
}
},
webpush: {
headers: {
image: 'https://foo.bar.pizza-monster.png'
}
},
topic: topicName,
};
getMessaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
REST
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"topic":"industry-tech",
"notification":{
"title":"Sparky says hello!",
},
"android":{
"notification":{
"image":"https://foo.bar/pizza-monster.png"
}
},
"apns":{
"payload":{
"aps":{
"mutable-content":1
}
},
"fcm_options": {
"image":"https://foo.bar/pizza-monster.png"
}
},
"webpush":{
"headers":{
"image":"https://foo.bar/pizza-monster.png"
}
}
}
}
Consultez la documentation de référence HTTP v1 pour obtenir des informations détaillées sur les clés disponibles dans les blocs spécifiques à la plate-forme dans le corps du message.
Avec notification
défini comme indiqué, cette requête d'envoi permet au client destinataire de gérer l'image fournie dans la charge utile.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/16 (UTC).
[null,null,["Dernière mise à jour le 2025/08/16 (UTC)."],[],[],null,["The FCM HTTP v1 API and the\n[Notifications composer](//console.firebase.google.com/project/_/notification)\nsupport sending image links in the payload of a display\nnotification, for image download to the device after delivery.\nImages for notifications are limited to 1MB in size, and otherwise are\nrestricted by native Android\n[image support](https://developer.android.com/guide/topics/media/media-formats#image-formats).\n\nBuild the send request\n\nIn your notification send request, set the following [AndroidConfig](/docs/reference/fcm/rest/v1/projects.messages#AndroidConfig)\noption:\n\n- `notification.image` containing the image URL\n\nThe following example send request sends a common notification title to all platforms, but it also sends an image. Here's an approximation of the\nvisual effect on a user's device:\n\nNode.js \n\n const topicName = 'industry-tech';\n\n const message = {\n notification: {\n title: 'Sparky says hello!'\n },\n android: {\n notification: {\n imageUrl: 'https://foo.bar.pizza-monster.png'\n }\n },\n apns: {\n payload: {\n aps: {\n 'mutable-content': 1\n }\n },\n fcm_options: {\n image: 'https://foo.bar.pizza-monster.png'\n }\n },\n webpush: {\n headers: {\n image: 'https://foo.bar.pizza-monster.png'\n }\n },\n topic: topicName,\n };\n\n getMessaging().send(message)\n .then((response) =\u003e {\n // Response is a message ID string.\n console.log('Successfully sent message:', response);\n })\n .catch((error) =\u003e {\n console.log('Error sending message:', error);\n });\n\nREST \n\n POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1\n\n Content-Type: application/json\n Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA\n {\n \"message\":{\n \"topic\":\"industry-tech\",\n \"notification\":{\n \"title\":\"Sparky says hello!\",\n },\n \"android\":{\n \"notification\":{\n \"image\":\"https://foo.bar/pizza-monster.png\"\n }\n },\n \"apns\":{\n \"payload\":{\n \"aps\":{\n \"mutable-content\":1\n }\n },\n \"fcm_options\": {\n \"image\":\"https://foo.bar/pizza-monster.png\"\n }\n },\n \"webpush\":{\n \"headers\":{\n \"image\":\"https://foo.bar/pizza-monster.png\"\n }\n }\n }\n }\n\nSee the\n[HTTP v1 reference documentation](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages)\nfor complete detail on the keys available in platform-specific blocks in the\nmessage body.\n\nWith `notification` set as shown, this send request enables the receiving client\nto handle the image delivered in the payload."]]