Patch #19116


Added by Lucile Quirion over 7 years ago. Updated over 5 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:


Category:REST API
Target version:3.4.0


To integrate Redmine with our CI tool (Jenkins), I need to be able to upload files via the REST API.

This patch add the Files REST API for:
- getting the list of files for a project and its versions.
- creating new files from uploaded attachments.

Apply on svn revision r14015
Formatted with git
Related Issues: #7725, #18245 and #13800

0001-REST-API-add-files-REST-API.patch Magnifier (9.41 KB) Lucile Quirion, 2015-02-16 20:21

0001-REST-API-add-files-REST-API_v2.patch Magnifier (9.43 KB) Lucile Quirion, 2015-02-19 17:07

0001-REST-API-add-files-REST-API_v3.patch Magnifier (8.48 KB) Jake Kemme, 2016-07-22 19:07

Related issues

Related to Redmine - Feature #7725: REST API for files Closed 2011-02-25
Related to Redmine - Feature #18245: Documents REST API New
Related to Redmine - Feature #13800: File REST API New

Associated revisions

Revision 16109
Added by Jean-Philippe Lang over 5 years ago

Files REST API (#19116).

Patch by Lucile Quirion and Jake Kemme.


#1 Updated by Lucile Quirion over 7 years ago

  • Category set to REST API

#2 Updated by Lucile Quirion over 7 years ago

  • Description updated (diff)
  • Status changed from New to Needs feedback

#3 Updated by Jean-Philippe Lang over 7 years ago

  • Assignee set to Lucile Quirion

That's a good start but here are a few things that need to be changed:

  • I'll prefer to keep only one resource for project files, which would be /projects/:project_id/files, so we should remove the alternate POST /projects/foo/versions/123/files to create a file associated to a version (POST /projects/foo/files with a version_id attribute will be used instead).
  • POST /projects/:project_id/files should create a single file with the file attributes given in a "file" hash (instead of attachments / file_1 ), eg.
{ "file": {
  "filename": "foo",
  • GET /projects/:project_id/files should include the names of author and version (if any), just like it's done for the issues, eg.: => file.author_id, :name =>

  • Maybe should simply use the AttachmentsHelper#render_api_attachment to format most of the file attributes
  • We don't keep track of authors in the source code
  • I hold the copyright for the Redmine source code, I can't include a source file that is copyrighted to a third-party in the core.

#4 Updated by Lucile Quirion over 7 years ago

Thanks for the feedback, I'll modify my patch.

Concerning the POST request, would the following JSON be acceptable ?

{ "project": {
    "version_id": "123",
    "files": [
      { "filename": "file_1",
        "description": "",
        "content_type": "",
        "token": "foo_1" 
      { "filename": "file_2",
        "token": "foo_2" 

Where version_id, filename, description and content_type are optional parameters.

This way it will be possible to handle several files at once (as done in the IssuesController).

#5 Updated by Lucile Quirion over 7 years ago

Here is the updated patch.
The expected JSON format is

{ "file": {

I used the AttachmentsHelper#render_api_attachment, which I've modified to accept additional options (in order to diplay the version_id).
I can remove this modification if necessary.

#6 Updated by Lucile Quirion over 7 years ago

  • Assignee changed from Lucile Quirion to Jean-Philippe Lang

#7 Updated by Toshi MARUYAMA about 7 years ago

#8 Updated by Toshi MARUYAMA about 7 years ago

#9 Updated by Toshi MARUYAMA about 7 years ago

#10 Updated by Marco Descher over 6 years ago

Any chance this will be part of an upcoming release? :)

#11 Updated by Larry Owen over 6 years ago

What's the status on this feature? Sure would be helpful.

#12 Updated by Go MAEDA over 6 years ago

The patch 0001-REST-API-add-files-REST-API_v2.patch cannot be applied to current trunk (r15012).

$ patch -p1 < 0001-REST-API-add-files-REST-API_v2.patch
patching file app/controllers/files_controller.rb
Hunk #3 FAILED at 49.
1 out of 3 hunks FAILED -- saving rejects to file app/controllers/files_controller.rb.rej
patching file app/helpers/attachments_helper.rb
patching file app/views/files/index.api.rsb
patching file test/integration/api_test/api_routing_test.rb
patching file test/integration/api_test/files_test.rb

#13 Updated by Jake Kemme almost 6 years ago

Updated Patch from Hg attached. We are currently using on 3.3 with no issues.

#14 Updated by Toshi MARUYAMA almost 6 years ago

  • Status changed from Needs feedback to New
  • Target version set to 3.4.0

#15 Updated by Jean-Philippe Lang over 5 years ago

  • Status changed from New to Closed

Committed in r16109 with a few changes to the index response. Thanks.

Also available in: Atom PDF