limited-library-71452
04/18/2024, 2:14 PMfresh-fireman-491
04/18/2024, 2:24 PMfresh-fireman-491
04/18/2024, 2:24 PMlimited-library-71452
04/18/2024, 2:27 PMjolly-policeman-82775
04/18/2024, 2:35 PMjolly-policeman-82775
04/18/2024, 2:35 PMjolly-policeman-82775
04/18/2024, 2:35 PMjolly-policeman-82775
04/18/2024, 2:35 PMfresh-fireman-491
04/18/2024, 2:41 PMlimited-library-71452
04/18/2024, 2:51 PMlimited-library-71452
04/18/2024, 2:52 PMlimited-library-71452
04/18/2024, 3:04 PMfresh-fireman-491
04/18/2024, 3:07 PMfresh-fireman-491
04/18/2024, 3:07 PMjolly-policeman-82775
04/18/2024, 3:07 PMlimited-library-71452
04/18/2024, 3:13 PMfresh-fireman-491
04/18/2024, 3:14 PMfresh-fireman-491
04/18/2024, 3:14 PMbumpy-addition-21507
04/18/2024, 3:18 PMfresh-fireman-491
04/18/2024, 3:18 PMlimited-library-71452
04/18/2024, 3:23 PMfresh-fireman-491
04/18/2024, 3:23 PMfresh-fireman-491
04/18/2024, 3:24 PMfresh-fireman-491
04/18/2024, 3:24 PMjavascript
const whatsappAccessToken = env.WHATSAPP_ACCESS_TOKEN
const res = await axios.get(event.payload.imageUrl, {
headers: {
Authorization: `Bearer ${whatsappAccessToken}`,
},
})
// This will be a JavaScript Buffer (https://nodejs.org/api/buffer.html) containing the raw binary content of the media file.
const rawFileContent = res.data
// This will indicate the file type, see:
// https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media/#supported-media-types
const mimeType = res.headers['content-type']
fresh-fireman-491
04/18/2024, 3:25 PMlimited-library-71452
04/18/2024, 3:33 PMfresh-fireman-491
04/18/2024, 4:02 PMlimited-library-71452
04/18/2024, 4:32 PMlimited-pencil-78283
04/18/2024, 4:49 PMlimited-pencil-78283
04/18/2024, 5:47 PMlimited-library-71452
04/18/2024, 5:59 PMlimited-pencil-78283
04/18/2024, 6:00 PMlimited-library-71452
04/18/2024, 6:06 PMjolly-policeman-82775
04/18/2024, 6:07 PMfresh-fireman-491
04/18/2024, 6:13 PMjolly-policeman-82775
04/18/2024, 6:13 PMhundreds-battery-97158
04/19/2024, 7:44 AMhundreds-battery-97158
04/19/2024, 7:46 AMhundreds-battery-97158
04/19/2024, 8:04 AMlimited-library-71452
04/19/2024, 8:16 AMlimited-library-71452
04/19/2024, 7:01 PMlimited-library-71452
04/19/2024, 7:17 PMhundreds-battery-97158
04/19/2024, 7:23 PMhundreds-battery-97158
04/19/2024, 7:25 PMlimited-library-71452
04/19/2024, 7:27 PMlimited-library-71452
04/22/2024, 2:32 PMhundreds-battery-97158
04/25/2024, 12:18 PMlimited-library-71452
04/25/2024, 1:54 PMlimited-library-71452
04/25/2024, 1:55 PMhundreds-battery-97158
04/26/2024, 7:37 PMhundreds-battery-97158
04/26/2024, 7:38 PMhundreds-battery-97158
04/26/2024, 7:40 PMlimited-library-71452
04/30/2024, 7:40 AMhundreds-battery-97158
04/30/2024, 9:51 AMhundreds-battery-97158
04/30/2024, 9:53 AMlimited-library-71452
05/02/2024, 10:01 AMlimited-library-71452
05/02/2024, 11:39 AMlimited-library-71452
05/02/2024, 11:41 AMlimited-library-71452
05/02/2024, 11:43 AMfresh-fireman-491
05/02/2024, 12:30 PMlimited-library-71452
05/02/2024, 1:00 PMlimited-library-71452
05/02/2024, 1:00 PMlimited-library-71452
05/02/2024, 1:08 PMlimited-library-71452
05/02/2024, 1:09 PMlimited-library-71452
05/02/2024, 1:18 PMlimited-library-71452
05/02/2024, 1:19 PMhundreds-battery-97158
05/02/2024, 8:38 PMlimited-library-71452
05/03/2024, 7:57 AMhundreds-battery-97158
05/03/2024, 1:02 PMlimited-library-71452
05/03/2024, 4:27 PMfresh-fireman-491
05/03/2024, 5:42 PMlimited-library-71452
05/04/2024, 4:33 PMfresh-fireman-491
05/08/2024, 3:56 PMhundreds-battery-97158
05/10/2024, 4:00 PMhundreds-battery-97158
05/10/2024, 4:00 PMlimited-library-71452
05/14/2024, 8:20 PMclean-photographer-30160
05/15/2024, 1:39 PMclean-photographer-30160
05/15/2024, 1:39 PMclean-photographer-30160
05/15/2024, 5:43 PMclean-photographer-30160
05/21/2024, 5:39 PMclean-photographer-30160
05/21/2024, 5:48 PMtry {
const res = await axios.get(event.payload.imageUrl, {
headers: {
Authorization: `Bearer ${env.WHATSAPP_ACCESS_TOKEN}`,
},
responseType: 'arraybuffer'
});
const { data } = await axios.post(
"https://r86otig4qf.execute-api.us-east-2.amazonaws.com/s3-image-uploader-test",
res.data
)
workflow.dataFromImage = data.url
} catch (e) {
workflow.dataFromImage = 'error :('
}
clean-photographer-30160
05/21/2024, 5:48 PMclean-photographer-30160
05/21/2024, 5:49 PMconst res = await axios.get(event.payload.imageUrl, {
headers: {
Authorization: `Bearer ${env.WHATSAPP_ACCESS_TOKEN}`,
},
responseType: 'arraybuffer'
});
event.payload.imageUrl: The URL of the image you want to retrieve.
**axios.get**: Makes a GET request to that URL.
**headers: **Includes an authorization header with a WhatsApp access token.
**responseType: 'arraybuffer': **Specifies that the response should be treated as an arraybuffer, which is useful for handling binary data like images.
Using axios to make a POST request to an image upload service:
const { data } = await axios.post(
"https://r86otig4qf.execute-api.us-east-2.amazonaws.com/s3-image-uploader-test",
res.data
)
Service URL: "https://r86otig4qf.execute-api.us-east-2.amazonaws.com/s3-image-uploader-test"
res.data: The body of the response from the GET request, which contains the image data.
axios.post: Makes a POST request to the service URL with the image data.
Storing the URL of the uploaded image:
workflow.dataFromImage = data.url
data.url: Assigns the URL of the uploaded image (provided by the upload service) to workflow.dataFromImage.
Error handling:
javascript
Copy code
} catch (e) {
workflow.dataFromImage = 'error :('
}
**catch**: Catches any errors that occur during the execution of the GET or POST requests.
**workflow.dataFromImage = 'error :('**: If an error occurs, it assigns the value 'error :(' to workflow.dataFromImage.
Summary
This code retrieves an image from a URL using an authorization token, then uploads that image to a specified service and stores the URL of the uploaded image in a variable. If any error occurs during the process, it catches the error and stores an error message instead of the URL.clean-photographer-30160
05/21/2024, 5:51 PMlimited-library-71452
05/24/2024, 8:44 AMhundreds-battery-97158
05/24/2024, 11:07 AMclean-photographer-30160
05/24/2024, 7:11 PMclean-photographer-30160
05/24/2024, 7:13 PMclever-horse-5574
05/26/2024, 4:14 PMbusy-art-73803
07/10/2024, 6:14 AM