Convert URL to base64 format.

To convert a URL in to base64 format:

       function convertUrlToBase64(imageUrl) {
                        // Make a GET request to the image URL
                        let response = https.get({
                                url: imageUrl
                        });
                        // Get the response headers
                        let headers = response.headers;
                        // Extract the content type header, which contains the image type
                        let contentType = headers['content-type'];
                        // Extract the image type from the content type header
                        let imageType = contentType.split('/').pop().toLowerCase();
                        // Get the response body as base64 data
                        let base64Data = response.body.toString('base64');
                        return {
                                base64Data: base64Data,
                                imageType: imageType
                        };
                }

Leave a comment

Your email address will not be published. Required fields are marked *