Want to post image via API and request is giving 201 as well but it’s showing “It looks like we don’t support this file format” while opening the image.
please find details filled in http request:
body: application/json
content-type: image/png
file path in http request {Options - Attachment section}
in my old company i had the same problem as you,
this is how i did it
step 1. i used UiPath codeflow
step 2. used RestSharp
step 3. convert image to base64
in SNOW APIs we are asked to not convert the image into base64 and directly pass the file path.
Also, we didn’t convert the file into base64 in postman. We just used body as binary and passed the file there
If you can give the postman collection…if it is ok…please share …even personal message if you dont want to share here…I can check from here on how exactly it should be
Try
’ Define ServiceNow instance details
Dim serviceNowUrl As String = in_UploadAttachEndpointURL
Dim bearerToken As String = in_bearerToken
’ The sys_id of the incident to attach the image to
Dim incidentSysId As String = in_incidentNumberSysID
’ The file path of the image to be uploaded
Dim filePath As String = in_filePath
’ Convert the image to Base64
Dim fileBytes As Byte() = System.IO.File.ReadAllBytes(filePath)
’ Dim base64File As String = Convert.ToBase64String(fileBytes)
’ Upload the image
Using client As New system.Net.Http.HttpClient()
’ Set Bearer Token Authorization header
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Bearer”, bearerToken)
’ Prepare the JSON payload
’ Prepare the file content To be uploaded
Using fileStream As New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim content As New MultipartFormDataContent()
’ Create StreamContent for the file
Dim fileContent As New StreamContent(fileStream)
fileContent.Headers.ContentType = New MediaTypeHeaderValue(“image/png”) ’ Change to ‘image/png’ if needed
’ Add content to the multipart form data
content.Add(fileContent, “file”, Path.GetFileName(filePath))
content.Add(New StringContent(incidentSysId), “table_sys_id”)
content.Add(New StringContent(“incident”), “table_name”)
’ Make the POST request
Dim response As HttpResponseMessage = client.PostAsync(serviceNowUrl, content).Result
out_Response = CInt(response.StatusCode)
out_ResponseMessage = response.ReasonPhrase
End Using
End Using
Catch ex As Exception
out_Exception = ex.message
End Try
Using this invoke code activity. Can anyone help with it as it’s giving bad request and 400.