Feature #7725

REST API for files

Added by Alex Last over 6 years ago. Updated 9 months ago.

Status:ClosedStart date:2011-02-25
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:REST API
Target version:-
Resolution:Duplicate

Description

would be nice to have the API to manipulate files remotely.
e.g. to upload new distributives using some automated scripts.


Related issues

Related to Redmine - Feature #18245: Documents REST API New
Related to Redmine - Feature #13800: File REST API New
Related to Redmine - Patch #19116: Files REST API Closed
Duplicated by Redmine - Feature #20404: REST API support for project files (attachments) Closed

History

#1 Updated by j dlx over 6 years ago

Alexey Skor wrote:

would be nice to have the API to manipulate files remotely.
e.g. to upload new distributives using some automated scripts.

Well for starters even a simple files list would do for me..
right now the only way (i know of) is to filter activity..

May i ask the maintainer/some official to get some word out on the files-API topic?

Reading through all/most threads regarding this topics, i still have no real clue if:

1. such a feature is planned (or at least considered) at all
2. if so, if there's a roadmap or something?

thx,
Jan

#2 Updated by Gert van Dijk over 5 years ago

Lately, some progress is made on the REST API features like the file attachments - see #8171. However, as far as I can see from the current documentation, it's still not possible to manage a project's 'Files' and 'Documents' using the REST API.

I would also like to see this feature for automated uploading of files; e.g. test builds after automated building in a post-receive/post-commit hook.

#3 Updated by Gert van Dijk over 5 years ago

In the meantime I created a Python script to overcome this. See redmine-file-uploader on GitHub.

I can now upload my builds from the build server to Redmine in the 'Files' section of the project for internal testing/deployment.
For anyone also in need of this; hope this helps.

#4 Updated by Bengt L├╝ers over 4 years ago

The linked script works fine for uploading, but I would like to download files to mirror them in a Git repository. Is there any chance that this will make it into the API, soon or do I have to write something that does the downloading in the same fashion?

#5 Updated by Dmitry Popov over 4 years ago

Thanks, Gert! Your script works like a charm!

But still, API support would be appreciated.

#6 Updated by Dmitry Popov over 4 years ago

I've rewritten the script in Ruby:

require 'mechanize'

# Replaces \ with / and removes " 
ARGV.map!{|a|a.gsub('\\','/').gsub(/^"(.+)"$/,'\\1')}

filename    = ARGV[0] || abort('Filename must be specified')
puts "File:              #{filename}" 
url         = ARGV[1] || abort('Redmine URL must be specified')
puts "Redmine URL:       #{url}" 
username    = ARGV[2] || abort('Redmine username must be specified')
puts "Username:          #{username}" 
password    = ARGV[3] || abort('Redmine password must be specified')
puts "Password:          #{'*' * password.length}" 
project     = ARGV[4] || abort('Redmine project must be specified')
puts "Project:           #{project}" 

login_page_path = '/login'
files_page_path = '/projects/' + project + '/files'

agent = Mechanize.new

# No certificate verification (I had to use this hack because our server is bound to custom port)
# agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE

agent.get(URI.join(url, login_page_path)) do |login_page|
  login_page.form_with(:action => login_page_path) do |login_form|
    login_form.username = username
    login_form.password = password
  end.submit
end

agent.get(URI.join(url, files_page_path + '/new')) do |upload_page|
  upload_page.form_with(:action => files_page_path) do |upload_form|
    upload_form.file_uploads.first.file_name = filename
  end.submit
end

Here's the script to delete uploaded files:

agent.get(URI.join(url, files_page_path)) do |files_page|
  file_link = files_page.link_with(:text => File.basename(filename))
  if file_link
    file_id = file_link.href.match(/download\/(\d+)/)[1].to_i
    agent.post(URI.join(url, "/attachments/#{file_id}"), {'_method' => 'delete', 'authenticity_token' => files_page.at('meta[@name="csrf-token"]')[:content]})
  end
end

#7 Updated by Lucile Quirion over 2 years ago

I also need a REST API for uploading files and noted that there is several open tickets concerning that feature (#18245, #13800)

So I've started working on it.
I'll try to include the patch submitted in #13800

#8 Updated by Toshi MARUYAMA over 2 years ago

#9 Updated by Toshi MARUYAMA over 2 years ago

#10 Updated by Toshi MARUYAMA over 2 years ago

#11 Updated by Mischa The Evil about 2 years ago

  • Duplicated by Feature #20404: REST API support for project files (attachments) added

#12 Updated by Go MAEDA 9 months ago

  • Status changed from New to Closed
  • Resolution set to Duplicate

Implemented by #19116, will be available in upcoming 3.4.0.

Also available in: Atom PDF