Project

General

Profile

Actions

Patch #19116

closed

Files REST API

Added by Lucile Quirion almost 10 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Category:
REST API
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Context:
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


Files


Related issues

Related to Redmine - Feature #7725: REST API for filesClosed2011-02-25

Actions
Related to Redmine - Feature #18245: Documents REST APINew

Actions
Related to Redmine - Feature #13800: File REST APINew

Actions
Actions #1

Updated by Lucile Quirion almost 10 years ago

  • Category set to REST API
Actions #2

Updated by Lucile Quirion almost 10 years ago

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

Updated by Jean-Philippe Lang almost 10 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.:

    api.author(:id => file.author_id, :name => file.author.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.
Actions #4

Updated by Lucile Quirion almost 10 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).

Actions #5

Updated by Lucile Quirion almost 10 years ago

Here is the updated patch.
The expected JSON format is

{ "file": {
    "filename",
    ...
  }
}

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.

Actions #6

Updated by Lucile Quirion almost 10 years ago

  • Assignee changed from Lucile Quirion to Jean-Philippe Lang
Actions #7

Updated by Toshi MARUYAMA almost 10 years ago

Actions #8

Updated by Toshi MARUYAMA almost 10 years ago

Actions #9

Updated by Toshi MARUYAMA almost 10 years ago

Actions #10

Updated by Marco Descher about 9 years ago

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

Actions #11

Updated by Larry Owen almost 9 years ago

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

Actions #12

Updated by Go MAEDA almost 9 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
Actions #13

Updated by Jake Kemme over 8 years ago

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

Actions #14

Updated by Toshi MARUYAMA over 8 years ago

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

Updated by Jean-Philippe Lang about 8 years ago

  • Status changed from New to Closed

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

Actions

Also available in: Atom PDF