Project

General

Profile

How to download attachments using rest api?

Added by Parikshit Chaudhary 2 months ago

Hi Team,

I'm using this GET "https://redmine_url/issues.json/?issue_id=1&include=attachments" to get the issue data including attachments. In the response I'm getting "content_url": "http://redmine_url/attachments/download/2/Chapter.docx" that is a downloadable link.

When I'm trying to hit this url in postman by using POST method, Basic Auth and providing username & password I'm getting "Connection Time Out Error."
I've also tried to hit this content-url in incognito tab and using java code, but I'm getting same "Connection Time Out Error".

Can you please help me, how we can download the attachments using code/rest API/Redmine java library?

Regards,
Parikshit


Replies (3)

RE: How to download attachments using rest api? - Added by Holger Just 2 months ago

From your redacted URLs, it appears that you are accessing your Redmine via https while the generated content_url uses http. If that is actually the case, your Redmine may be configured incorrectly. If you are the admin, please check the settings in Administration -> Settings to be correct for the external URL.

As for actually downloading the attachment, you should use a GET request to the content_url using your usual API authentication mechanism.

RE: How to download attachments using rest api? - Added by Parikshit Chaudhary 2 months ago

Thanks, Holger Just for your prompt response.

As I'm new to Redmine, can you please help with how to correct it? Because I'm getting http in my content_url instead of https.

What do I need to do so that I can get content_url in the https form?

Thanks in advance.

Regards,
Parikshit

RE: How to download attachments using rest api? - Added by Holger Just 2 months ago

Well, it seems that your webserver does not properly inform your application server that the initial request was made over https. Thus, the application server (and thus Redmine) assumes that it was made over plain http. To fix this, you likely have to adapt your webserver config, depending on your exact setup.

Depending on your webserver, this usually requires setting an additoional request header before passing along the request to the application server. With Apache, this can look like this in your SSL virtual host:

RequestHeader set X-Forwarded-Proto "https" 

With nginx, this can look like this in your SSL server

proxy_set_header X-Forwarded-Proto https;

It depends on your specific setup where exactly you need to set these headers in your configuration.

    (1-3/3)