It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

401 error in downloading attachment contetn through RestAPI

I am trying to download attachment of issue through code using Attachment Content URL.

 

But for some file names having Special Characters like '(',')' or chinese Literals like '機能', I get 401 unauthorized message.

Let me know if there is some way through which we can get attachment content.

1 answer

0 votes

Hello @Asif Diwan ,

Welcome to the Atlassian Community. 

From information provided so far I understand that:

  1. You are using the issue REST API endpoint to get the attachment content URL
  2. When trying to download the attachment content URL for files having non-standard characters the call fails and you get error 401

Can you kindly confirm my understanding is correct?

 

In case it is, can you check if this works using Curl?

Please see below example for details on how to do so. Also, make sure to remove the sensitive data as I did below and paste the results in your reply:

curl -D- -L -u EMAIL:API-TOKEN -H "Accept: application/json" https://HOSTNAME/secure/attachment/10000/ycBsQT7.jpg -o file.jpg


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

HTTP/2 302 

server: AtlassianProxy/1.15.8.1
cache-control: no-cache, no-store, must-revalidate
content-type: image/jpeg
strict-transport-security: max-age=315360000; includeSubDomains; preload
date: Wed, 25 Sep 2019 14:45:19 GMT
atl-traceid: babfca7aab34c384

[REMOVED SENSITIVE CONTENT]

 

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

HTTP/2 200 
date: Wed, 25 Sep 2019 14:45:20 GMT
content-type: image/jpeg
content-length: 34498

[REMOVED]

content-disposition: inline; filename="ycBsQT7.jpg"
cache-control: private
x-envoy-upstream-service-time: 244
strict-transport-security: max-age=31536000; preload
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
server: globaledge-envoy

 

100 34498  100 34498    0     0  31591      0  0:00:01  0:00:01 --:--:-- 31591

 

In case my understanding is not correct. Please provide more details.

 

Cheers,
Dario

Hi @Dario ,

Thanks for your reply.

I have an addon and using addon key we are trying to get attachment using rest api end point.

So far I was successful in getting all attachments using this rest api end point.

But for file having special characters in its name I get 401 unauthorized request error.

Thanks,

Asif

Dario Atlassian Team Oct 03, 2019

Thanks for your reply @Asif Diwan ,

I will try to reproduce the issue having a file name with a comma, also if there are chances that this is failing since the comma can be seen as a delimiter, like explained also in:

 

For the rest, could you kindly provide more details on what is the 機能 character and what other characters are known to causing this issue? 

 

Cheers,
Dario

Dario Atlassian Team Oct 04, 2019

Hi @Asif Diwan ,

I cannot reproduce the issue. Attaching an image having a comma in the filename to a Jira issue and then downloading it using REST API works fine on my side (I use Linux). Please see below for more details:

File name: cannot-quote,list.png

Getting attachment content url:

"content": "https://NAME.atlassian.net/secure/attachment/10005/cannot-quote%2Clist.png",
"thumbnail": "https://NAME.atlassian.net/secure/thumbnail/10005/cannot-quote%2Clist.png"

Downloading the file:

curl -D- -L -u EMAIL:API-TOKEN -H "Accept: application/json" https://NAME.atlassian.net/secure/attachment/10005/cannot-quote%2Clist.png -o image.png
 

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0 HTTP/2 302 

 
server: AtlassianProxy/1.15.8.1
cache-control: no-cache, no-store, must-revalidate
content-type: image/png

[REMOVED SENSITIVE CONTENT]

 

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0 HTTP/2 200 

 
date: Fri, 04 Oct 2019 16:33:28 GMT
content-type: image/png
content-length: 37963

[REMOVED]

content-disposition: attachment; filename="cannot-quote,list.png"
[...]

100 37963  100 37963    0     0  30129      0  0:00:01  0:00:01 --:--:-- 72448

 

Now, if this still does not work for you, can you kindly let me know which Operating System you are using and how you are downloading the attachment?

Also, can you kindly perform the same test I did above using Curl and copy paste the results (removing sensitive data) into your answer? 

 

Cheers,
Dario

Don't use CURL @Dario 

Instead use Jira Rest API to get attachment.

Use Addon Key for authentication. As an addon developer I don't have client's credentials. So I have to use Addon User and Key details for authentication.

Let me know if you need more details.

Thanks,

Asif

Dario Atlassian Team Oct 08, 2019

Hi @Asif Diwan ,

Please notice that Curl is just one of the many software available that you can use in order to send a REST API request to a given endpoint. 

Being curl a text only software, I asked to use it to try to reproduce the issue so that it would be possible to easily paste the results of the test in here. 

This is because I already tried reproducing the issue by attaching a file with a comma in the name but everything worked fine for me (the curl output is available in my previous post).

Therefore, I need you to run the same test so that we can try narrow down the issue: 

  • if everything works fine when using curl then the attachment endpoint is behaving as expected and problem is on your side (with the add-on code or anything similar)
  • if you can reproduce the issue using curl as well then the problem is with the REST API endpoint (our side)

 

Also, please notice that I only tried to reproduce the issue by attaching a file having a comma in the name. As already mentioned: 

could you kindly provide more details on what is the 機能 character and what other characters are known to causing this issue? 

 

Finally, for the future, please notice that this is not the best place to get help on development  related questions. The right resources are listed in https://developer.atlassian.com/resources. 

Specifically:

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

229 views 1 2
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you