Cannot download base64 image from a browser from an aws lambda function? - node.js

I create a node js lambda function to crop and return an image from any image url.
The function creates a GET API which returns a cropped image.The API is working fine, I am able to download any image from postman but even there I am not getting the image preview, I have to manually download. Although the downloaded base64 image is correct and working in the browser if put directly.
I need a way for it to work directly in the html <img> tag.
The api is something like - https://aws-lambda-fn-image-resizer/{encoded image url}

Related

Add sample image in template header in whatsapp cloud API

I am doing a project using WhatsApp cloud API. I need to create a template with a media header. I have created a template with a media header without a sample image and it gets rejected. So I want to create a template with a sample image in Node JS.
Template with a media header
Add sample image for a template
curl -X POST "https://graph.facebook.com/v14.0/{whatsapp-business-account-ID}/message_templates
?name={template-name}
&language=en_US
&category=TRANSACTIONAL,
&components=[{
type:BODY,
text:{message-text}
},
{
type:HEADER,
format:IMAGE,
example:{header_handle:[{uploaded-image-file-url}]}
}],
&access_token={system-user-access-token}"
I want to add a sample image using Node JS (Not manually like the second picture).
header_handle requires a encrypted file upload provided by facebook.
This can be done by calling 2 apis.
First,
We have to create a session for the file to be uploaded.
For creating session refer this
After creating session, we will get session id to upload the original file to it.Response will look something like this:
{"id":"upload:MTphdHRhY2htZW50Ojlk2mJiZxUwLWV6MDUtNDIwMy05yTA3LWQ4ZDPmZGFkNTM0NT8=?sig=ARZqkGCA_uQMxC8nHKI"}
Second,We have to upload the file to
https://graph.facebook.com/v14.0/{above_id}
This will give a response something similar to
{"h":"2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"}
Finally,
{header_handle:["2:c2FtcGxlLm1wNA==:image/jpeg:GKAj0gAUCZmJ1voFADip2iIAAAAAbugbAAAA:e:1472075513:ARZ_3ybzrQqEaluMUdI"]}
Should be added during the request to create template.
It worked for me.
See this for better understanding on how to do it.
The answer Provided by Aravindh is correct, you can follow This document from Meta to upload the Image you want.
Just make sure you use a supported type by WhatsApp API ( For WhatsApp Business Platform Cloud API , For WhatsApp Business Platform On-Premises API ) and the upload end point (file-type — The file's MIME type. Valid values are: image/jpeg, image/jpg, image/png, and video/mp4
)
Double Check if you are following exacly the types supported, for example in case of png, you need to set "file_type" to "image/png" no just "png" when creating the upload session.
I have tested it and it works for me.
Hope this helps

Adding image from google drive into google slideshow with API

I'm trying to add an image that I've uploaded to Drive via the Drive API into a slide show I've created using the same API.
when Running the fairly standard:
response = (self
._slides_service
.presentations()
.batchUpdate(presentationId=slide_deck_id, body=body)
.execute()
)
I get:
googleapiclient.errors.HttpError: <HttpError 400 when requesting {url} returned "Invalid requests[0].createImage: The provided image is in an unsupported format.">
I'm generating the service in the same way as suggested in the documentation here: https://developers.google.com/slides/quickstart/python
My scope is:
https://www.googleapis.com/auth/presentations
If I run the command with a random png from the internet then it inserts the image fine. I've tried the url provided by webContentLink or WebViewLink values from the response from uploading the images. Neither are valid.
What URL will work to do this?
I'm aware there are other similar questions on stack overflow but all of them are not related to doing this in python or if they are, there solutions don't work.
EDIT:
body is:
{'requests': [{'createImage': {'url': url, 'elementProperties': {'pageObjectId': page_id}}}]}
had to generalise the url and page id because GDPR is a pain.

How to attach a base64 png image in the slack bot's response? [duplicate]

I have integrated Slack API using cURL in my project.
I want to send an image as my attachment. It works while sending full image path in image_url. But when I convert that image to base64 string and then pass it with image_url it doesn't go as attachment.
So basically I want to post base64 string as my image attachment. Because I don't want to store the image on my server.
{"attachments":
[
{
"fallback": "Required text summary of the attachment that is shown by clients that understand attachments but choose not to show them.",
"image_url":"",
"text":"",
"color":"#7CD197"
}
]
}
You can not submit a full image as attachments, only URLs to an image.
If you want to upload an image to Slack you can do so by using files.upload. Here is a curl example for uploading a GIF image from the Slack documentation:
curl -F file=#dramacat.gif -F channels=C024BE91L,#general -F token=xxxx-xxxxxxxxx-xxxx https://slack.com/api/files.upload
An alternative is to use an image hoster (e.g. http://imgur.com) to upload and store your image (through their API). Then you can include the image URL in your attachment.
I personally prefer the second option, since its more flexible to include image URLs in messages and images then do not reduce your precious storage space on Slack.

Display image in Background Url from MongoDB using NodeJS and Angular6

I have created an image uploader on my site and store the URL in my MongoDB. I used this guide to create my image uploader: https://appdividend.com/2018/05/25/angular-6-file-upload-tutorial/
However, when the file is stored in my MongoDB table it is a C:\\fakepath\\ url. When I try to display the url in a background-image url field via ngStyle I get the response:
Cannot read property 'image' of undefined
Here is my code for the .html page:
<div class="jumbotron" [ngStyle]="{ 'background-image': 'url(' + post.image + ')'}"></div>
The rest of the code follows suit to the guide for storing the image.
If there is a way to either modify the url before it is in the MongoDB or to eliminate the C:\\fakepath\\ and just append the end to the ./upload/ folder where the image is stored should work as well. I have tried also just using the {{post.image}} syntax and recieve the same result.
Please check the network call if you're really receiving the data
(post and url) from backend.
If you are then check the logic where you assign the backend response to variable post.
From the error, it seems that post has no value. Or you accessing it
the wrong way. Check if post is yourCtrl.post or something.

How can I send an error image if the image can't be found in cloudinary (default image?)

I want to send an image that might say something like "Image coming soon".
In gridFS I can find out if an image exists and if it exist send the image if not I could tell it to send an error image.
Is there a place in cloudinary that has a sort of default image to send if it can't find the image requested like via the img src tag.
I would like something better than a broken image.
I use nodejs
When generating the image src URL with Cloudinary Node.js SDK, you can specify the default_image parameter:
cloudinary.image("non_existing_id.png", {default_image: "avatar.png"})
Or directly in the URL:
http://res.cloudinary.com/demo/image/upload/d_avatar.png/non_existing_id.png
You can read more about this here.

Resources