Jira dosen´t decode base64 attachment-request (REST API)

TieDall October 16, 2018

Hello,

i am trying to send attachments from an external ticket-system (BMC ITSM-Suite) to Jira. My request is working. It adds an attachment to an existing issue. But it seems like Jira is not decoding the data which is send in base64.

This is my request:

--W3NByNRZZYy4ALu6xeZzvWXU3NVmYUxoRB
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

[content of test.txt]
--W3NByNRZZYy4ALu6xeZzvWXU3NVmYUxoRB--

 

The content of my file is:

test

 

The content of the file in Jira is:

dGVzdA==

 

The content of the Jira file is the base64-coded content of the origin file.

Has someone had the same issue? Or has someone an idea what the problem could be?

Best Regards!

2 answers

1 accepted

0 votes
Answer accepted
Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 16, 2018

Dear @TieDall,

you have to envelope your attachment on your own. Jira doesn't process base64 files. So best you decode your attachment and then post them to the API:

See my Java snipplet for this:

import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.Header;

HttpPost postRequest = new HttpPost(url);
postRequest.addHeader(header);
MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.STRICT);
multipartEntity.addBinaryBody("file", new File(path));
postRequest.setEntity(multipartEntity.build());

 So long

Thomas

TieDall October 17, 2018

Hi @Thomas Deiler,

the external ticket-system can only send the file coded in base64. I have no chance to change that.

Is their no way to decode the file in Jira?

Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 17, 2018

Dear @TieDall,

I have checked the documentation a second time. Base64 is accepted as a MulitPartEntity mesasge. So I guess, that somehow what you send to Jira does not comply to RFC2388. Best you check how for example curl sends attachments to Jira and then reimplement this in your case.

If this doesn't work, implement a small proxy service (or script), that accepts Base64 attachments, file name and target issue key, to do the job for you.

So long

Thomas

TieDall October 18, 2018

Thank you, @Thomas Deiler!

I didn´t find any errors in my request. I solved the problem by implementing a small proxy service, as you mentioned earlier.

Best regards!

Muhammad Ramzan(Atlassian Certified Master)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2020

Hi,  i am facing same issue and trying to attach the file , could you please share the proxy service you created 

Michal Patoprsty June 18, 2020

Hi, @Muhammad Ramzan(Atlassian Certified Master) if you have a Jira server you can try to use our free addon from the marketplace which decodes your base64 encoded attachments.

https://marketplace.atlassian.com/apps/1221585/base64-attachment-upload-rest-api?hosting=server&tab=overview

Muhammad Ramzan(Atlassian Certified Master)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2020

Thanks  its amazing i installed and using it

蒋志强 February 10, 2023

Hi @Michal PatoprstyI'm using Jira cloud, and it says cannot be installed on this Cloud instance, Is there any other way?

Michal Patoprsty February 10, 2023

Hi @蒋志强 

Unfortunately, there is no Jira Cloud version of our Addon yet.

Althought we have started talking about implementing a Cloud version.

In the meantime you can create a feature request in our customer portal so we can keep you informed once it's in beta testing.

Michal

Israel Adonis Urbina Vargas August 24, 2023

It would help us a lot to have the app in Jira cloud

Ladislav Petruš August 25, 2023

A JIRA Cloud version of Base64 Upload plugin is currently in our pipeline and might be available in Q3 2023 in Atlassian marketplace.

I will post here once it is live.

Michal Patoprsty October 17, 2023

Hi @Israel Adonis Urbina Vargas , @蒋志强 

We have successfully released a JIRA Cloud version of Base64 Upload plugin

You can try and install it on your site.

However Cloud version has different installation methods so I would suggest first go through our Cloud documentation

We would be very grateful for every feedback you could provide as well as review of our app in marketplace.

 

If you would have any problems just let us know.

 

Michal

1 vote
Michal Patoprsty June 5, 2020

Hi guys,

in case anyone else have this kind of problem. We just recently released on marketplace Base64 Attachment Upload app which is decoding base64 attachments data on Jira Server side.

So if you don't want to implement your own service just install app on Jira and use one of provided endpoints.

Muhammad Ramzan(Atlassian Certified Master)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 3, 2020

@Michal Patoprsty , unfortunately its not supporting the service desk customers.

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><base64AttachmentUploadResult>    <errorMessage>Current user does not have EDIT_ISSUES permission for issue with id ISD-2!</errorMessage>    <result>ERROR</result></base64AttachmentUploadResult>

Ladislav Petrus _TEMPEST_ December 4, 2020

@Muhammad Ramzan(Atlassian Certified Master) , thank you for notifying us about this use case.

We have looked into the lifecycle of attachments that are created using the customer portal (the only place where sd customers can interact with Jira SD).  It works a little bit differently than the usual attachment lifecycle.   Any attachment that is submitted by customer user is always a part of a request comment. 

The Atlassian supported way to add an attachment as a customer user to a request is to use this rest endpoint: https://docs.atlassian.com/jira-servicedesk/REST/4.13.1/#servicedeskapi/request/{issueIdOrKey}/attachment-createAttachment .  This endpoint uses temporary files created by endpoint https://docs.atlassian.com/jira-servicedesk/REST/4.13.1/#servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile .  And the attachTemporaryFile endpoint does not support Base64 encoded attachments.

We can provide an alternative implementation of attachTemporaryFile in our plugin that will support Base64 attachments.  This implementation will return temporary attachment ids that can be then used in a call to https://docs.atlassian.com/jira-servicedesk/REST/4.13.1/#servicedeskapi/request/{issueIdOrKey}/attachment-createAttachment .  Would that be sufficient for you?

Like Michal Patoprsty likes this
Muhammad Ramzan(Atlassian Certified Master)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 4, 2020

That would be awesome and i think your addon will get more attractions to those who integrating service desk with third party like BMC Remedy 

Ladislav Petrus _TEMPEST_ December 4, 2020

@Muhammad Ramzan(Atlassian Certified Master) Thank you for confirmation, we will soon release a version of our plugin that will support creating temporary attachment / file ids.

Suggest an answer

Log in or Sign up to answer