Hi,
I'm trying to get attachment (image) content and convert it to base64 string using this endpoint GET /rest/api/3/attachment/content/{id}
I'm getting the content as escaped ascii unicode (I guess)
and it looks like this:
����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000d\u0000d\u0000\u0000��\u0000\u0011Ducky\u0000\u0001\u0000\u0004....
I've been trying to unescape it, convert manually etc. – nothing worked out.
Could you please confirm that this endpoint is working correctly, as I can see Experimental tag on it?
Could you please give me a hint how to decode this binary and convert it to base64?
Also, I think it could be helpful to give an option to download the attachment as base64 string, at lease for the images.
Thank you!
That content should be in bytes. You're getting binary string data. What you should do is write that content into a file data structure if you simply want to get the file data. If you want to convert to base64, I believe you could simply just convert the entire structure by decoding it to plain strings prior to using base64.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you give me an example how did you solve it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank u alot. But do you have how did u recieved it in back End? Since Iam using java spring boot. And the response while accessing the jira attachment link is 403. If u have any solution for it I would be thankful.
I want to download the ImageUrl from jira attachment content using java spring boot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
We are facing a similar issue where servicenow is expecting the attachment in Base64 format and failing. Is it possible for Jira to send the attachment in Base64 format? Please suggest.
The post that you are linking does it assume that Jira sending the attachment in Base64 format or the servicenow code in that article will convert in to Base64?
This is the API we are using: : https://api.atlassian.com/ex/jira/orgid/rest/api/3/attachment/content/id
If Jira cannot send the attachment in Base64 format we would like to get the servicenow code to convert binary (What Jira sends) to base64 format.
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Danil,
I have finally achieve 2 ways to resolve this.
we can get the BinaryArray you commented "����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000d\u0000d\u0000\u0000��\u0000\u0011Ducky\u0000\u0001\u0000\u0004...." making use of the Attachment Content API. You can test this on the Script Console:
def issueKey = 'EXAMPLE-1234'
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
def bodyfields = result.body.fields
def attachment = bodyfields.attachment[0]
def attachmentid = attachment.id
def attachmentfilename = attachment.filename
def attachmenttype = attachment.mimeType
def result2 = get('/rest/api/3/attachment/content/' + attachmentid)
.header('Content-Type', 'application/json')
.asBinary()
def attachmentcontent = result2.body.bytes.encodeBase64().toString()
You would need to use Automation for Jira and Webhooks by Zapier to send and capture attachment related data, such as filename, id, filetype (as you need) and in a second Zapier event you would need to use Code Python by Zapier and use this code:
import requests
import base64
import codecs
id = input_data['idattachment']
url = "https://yourdomain.attlassian.net/rest/api/3/attachment/content/"+id
r=requests.get(url , headers={"Content-Type":"application/json","Authorization":"Basic YOUR_TOKEN","Connection":"keep-alive"}, params={"redirect": "false"})attachment_bytes = r.content
base64input = codecs.encode(attachment_bytes,'base64').decode('utf-8')
attachment_text = bytes(base64input, 'utf-8').decode('utf-8')
return {'bytes':attachment_text }
in both ways you should be able to use the base64 encripted attachment to send it to another app.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not answering .. but can you share code sniffet how you getting attachemnt as byte[] using attachment api from java spring boot
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.