プロジェクト

全般

プロフィール

Vote #76061

完了

Files REST API

Admin Redmine さんが4年以上前に追加. 4年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
REST API_32
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
32
version_id:
119
issue_org_id:
19116
author_id:
121110
assigned_to_id:
1
comments:
15
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

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


journals

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
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.

<pre>
{ "file": {
"filename": "foo",
...
}
</pre>

* @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.
--------------------------------------------------------------------------------
Thanks for the feedback, I'll modify my patch.

Concerning the POST request, would the following JSON be acceptable ?
<pre>
{ "project": {
"version_id": "123",
"files": [
{ "filename": "file_1",
"description": "",
"content_type": "",
"token": "foo_1"
},
{ "filename": "file_2",
"token": "foo_2"
}
]
}
}
</pre>
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).
--------------------------------------------------------------------------------
Here is the updated patch.
The expected JSON format is
<pre>
{ "file": {
"filename",
...
}
}
</pre>

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.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Any chance this will be part of an upcoming release? :)
--------------------------------------------------------------------------------
What's the status on this feature? Sure would be helpful.
--------------------------------------------------------------------------------
The patch 0001-REST-API-add-files-REST-API_v2.patch cannot be applied to current trunk (r15012).

<pre>
$ 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
</pre>
--------------------------------------------------------------------------------
Updated Patch from Hg attached. We are currently using on 3.3 with no issues.
--------------------------------------------------------------------------------

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


related_issues

relates,Closed,7725,REST API for files
relates,New,18245,Documents REST API
relates,New,13800,File REST API

Admin Redmine さんが4年以上前に更新

  • カテゴリREST API_32 にセット
  • 対象バージョン3.4.0_119 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0