cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
709
Views
0
Helpful
6
Replies

Imagine preview not displaying (webex rest api)

Josh Flori
Level 1
Level 1

I follow the simple attachment post request here and post a jpg or pdf into a webex chat.

The preview does not display. But previews DO display when inserting manually.

Results are consistent across time.

Thoughts?

6 Replies 6

Jeff Marshall
Cisco Employee
Cisco Employee

Are you sending the attachment using a URL or sending as a local file upload?

Local file upload


Local file upload

That should work and this is a curl example where the .jpg file did render the preview correctly.

curl --location --request POST 'https://webexapis.com/v1/messages' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--form 'files=@"/Users/jeffmar/Downloads/Sample_Icon.jpg"' \
--form 'markdown="File sent using curl"' \
--form 'toPersonEmail="user@example.com"'

 

I'm having a similar issue working in Powershell, the image does send but no preview. Any suggestions?

 

 

$uri = "https://api.ciscospark.com/v1/messages"
$filePath = "C:\Users\Harry\Documents\WebexTestImage.png"

$file = Get-Item -Path $filePath

$form = @{
    toPersonEmail = "MYEMAIL"
    markdown = "TestImage"
    files = $file
}

$params = @{
    Method = "Post"
    Uri = $uri
    Form = $form
    Headers = @{"Authorization"="Bearer $Ciscobottoken"}
}

Invoke-WebRequest @params​

 

Running this request and looking at the raw HTTP, it looks like the Content-Type of the file part is set to "application/octet-stream" (i.e. a default/non-descript binary file type), whereas I suspect Webex is expecting this to be "image/png" if you want PNG image preview treatments.

dstaudt_0-1665085297237.png

The Curl and Python samples in the Webex docs re Message Attachments seem to indicate indicating the mime-type specifically like this is expected.

dstaudt_1-1665085554944.png

A bit of research didn't turn up a way to set a custom Content-Type for sub-parts using the PowerShell IWK -Form mechanism you're using.  If that's not possible, may need to construct the message using more "manual"/specific mechanisms, e.g.: https://get-powershellblog.blogspot.com/2017/09/multipartform-data-support-for-invoke.html