How to send local image to chat using incoming webhook - api

Facing issue while send the local image to google chat room using web hook.
attachment = open("images.jpg", "rb")
bot_message = {"cards": [{ "sections": [{"widgets": [{"image": attachment}]}]}]}
print (bot_message)
message_headers = {'Content-Type': 'application/json; charset=UTF-8'}
Error:
TypeError: Object of type BufferedReader is not JSON serializable

Issue roots from BufferedReader not JSON serializable which is caused by image widget expecting a URL instead.
Alternative is that, you need to upload your file to an image hosting site first (e.g. imgur) and then use the url of the posted image to the image widget's image url. For this one, see Imgur API docs.
Reference:
Image Widget requiring URL
uploading a file to imgur via python

Related

DocuSign CLM download PDF document

I'm following the api documentation trying to download a pdf document into PDF. I'm trying to simulate this in Postman first, before delving in code.
I have used many of their apis successfully, but can't get the download one. The docs say to download a document by id:
https://apidocsqana11.springcm.com/apidocs#!/Content/Content_Get
Implementation Notes Specify file type of document (image, PDF) in
ACCEPT header. Do not specify an ACCEPT header for native format
Response Class string
Response Content Type: application/json
So, I tried adding Accept and content-type as application/pdf in my postman to see if I will get a pdf document, but keep getting the response as normal json. I'm trying to get back a pdf doc not json response.

How to Upload Image From React Native To Express Server?

I am trying to upload a photo from an ios phone to an express server and I cannot seem to send the file to the server correctly. I am using react-native-image-picker and that gives me access to the photo's uri (location on the mobile phone). I am then trying to send that to the server like this:
const data = new FormData();
data.append('name', 'testName');
data.append('photo', {
uri: imageUriString,
type: 'image/jpeg',
name: 'testPhotoName'
});
I am then making a post request to the server with the body of the request being data.
The problem is that on the server side I am not getting the actual file. Instead I am getting the imageUriString which I cannot do anything with.
My req.files is undefined in the endpoint. (And I am parsing multipart/form-data so that is not the problem).
How do I upload the actual photo from React Native and receive it in req.file in Express?
I believe that you have to use var or let instead of const when using FormData. Reason being, since you are appending data to the variable, it needs to be able to change the contents of the variable's memory.

phoenix: show image from aws s3

I study the phoenix, create an application that loads the image on aws s3, and then displays it. I was able to upload the image to the cloud, but now it is not clear how to display it to the user on the page (I do not want to make public link to these images in the cloud). I was looking for information on this issue, but did not find anything useful.
From the clouds I get the file as binary data. Do I need to create some of these data is a temporary file that will be displayed on the page? I can display the image as base64, but I think this is not the best way. I would appreciate advice.
Since you've already fetched the image to a binary, you can just send it directly to the client with the appropriate content type and the browser will render it as an image. For example, to fetch and send the png at https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png:
def index(conn, _params) do
image = HTTPoison.get!("https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png").body
conn
|> put_resp_header("content-type", "image/png")
|> send_resp(200, image)
end
If you open this in your browser, you'll see the image being rendered correctly because of the content-type header.

facebook js api - HTML5 canvas upload as a photo

Is there a way to convert an HTML5 canvas to a some sort of an image format so that it can be uploaded to facebook users application album though the js api,
I'm currently successfully uploading an image link to an album with the following function:
FB.api('/me/photos', 'post', { message:'the message', url:imgURL});
Yes, there is way to convert HTML5 Canvas to an image. Following javascript function on the Canvas JS element will do this:
toDataURL('image/jpeg', 1.0);
You can have PNG also.
This function will generate a Base64 representation of the canvas image. I am not sure if you can directly give a Base64 string to the Facebook API.
If you can, then it will be great, otherwise you need to save it temporarily on the server and give that URL to the FB API.

Image url to byte array using Silverlight

How to convert image url to byte array or stream using Silverlight?
Easiest thing to do is use WebClient to download the Uri as a Stream. For this to work at least one of the following must be true:
The image is hosted on the same domain as the Silverlight app.
The domain that the image is hosted on is providing a clientaccesspolicy file to allow your Silverlight app to access the image.
This will give you access to the contents of the file as a Stream. If you want access to the decoded pixels rather than the raw contents of the file, load the Stream into an Image element (using BitmapSource.SetSource(Stream)), wait for the Image.ImageOpened event and then capture the Image element in a WriteableBitmap. You can then read the image pixel data from the WriteableBitmap.Pixels array. If the image is not coming cross-domain, you do not need to download the Stream and can just set the Image Source to the URI directly,