Name | kinto-attachment JSON |
Version |
7.0.0
JSON |
| download |
home_page | None |
Summary | Attach files to Kinto records |
upload_time | 2024-10-16 08:03:38 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2016 Mozilla Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
keywords |
web
services
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
================
Kinto Attachment
================
.. image:: https://github.com/Kinto/kinto-attachment/actions/workflows/test.yml/badge.svg
:target: https://github.com/Kinto/kinto-attachment/actions
.. image:: https://img.shields.io/pypi/v/kinto-attachment.svg
:target: https://pypi.python.org/pypi/kinto-attachment
Attach files to `Kinto records <http://kinto.readthedocs.io>`_.
Install
=======
::
pip install kinto-attachment
Setup
=====
In the Kinto project settings
.. code-block:: ini
kinto.includes = kinto_attachment
kinto.attachment.base_url = http://cdn.service.org/files/
Local File storage
------------------
Store files locally:
.. code-block:: ini
kinto.attachment.base_path = /tmp
S3 File Storage
---------------
Store on Amazon S3:
.. code-block:: ini
kinto.attachment.aws.access_key = <AWS access key>
kinto.attachment.aws.secret_key = <AWS secret key>
kinto.attachment.aws.bucket_name = <bucket name>
kinto.attachment.aws.acl = <AWS ACL permissions|public-read>
.. note::
``access_key`` and ``secret_key`` may be omitted when using AWS Identity
and Access Management (IAM).
See `Pyramid Storage <https://pythonhosted.org/pyramid_storage/>`_.
Google Cloud Storage
--------------------
.. code-block:: ini
kinto.attachment.gcloud.credentials = <Path to the Service Accounts credentials JSON file>
kinto.attachment.gcloud.bucket_name = <bucket name>
kinto.attachment.gcloud.acl = publicRead
See `Google Cloud ACL permissions <https://cloud.google.com/storage/docs/access-control/making-data-public>`_
The ``folder`` option
---------------------
With this option, the files will be stored in sub-folders.
Use the ``{bucket_id}`` and ``{collection_id}`` placeholders to organize the files
by bucket or collection.
.. code-block:: ini
kinto.attachment.folder = {bucket_id}/{collection_id}
Or only for a particular bucket:
.. code-block:: ini
kinto.attachment.resources.blog.folder = blog-assets
Or a specific collection:
.. code-block:: ini
kinto.attachment.resources.blog.articles.folder = articles-images
The ``keep_old_files`` option
-----------------------------
When set to ``true``, the files won't be deleted from disk/S3 when the associated record
is deleted or when the attachment replaced.
.. code-block:: ini
kinto.attachment.keep_old_files = true
Or only for a particular bucket:
.. code-block:: ini
kinto.attachment.resources.blog.keep_old_files = false
Or a specific collection:
.. code-block:: ini
kinto.attachment.resources.blog.articles.keep_old_files = true
The ``randomize`` option
------------------------
If you want uploaded files to be stored with a random name (default: True):
.. code-block:: ini
kinto.attachment.randomize = true
Or only for a particular bucket:
.. code-block:: ini
kinto.attachment.resources.blog.randomize = true
Or a specific collection:
.. code-block:: ini
kinto.attachment.resources.blog.articles.randomize = true
The ``extensions`` option
-------------------------
If you want to upload files which are not in the default allowed extensions (see `Pyramid extensions groups <https://pythonhosted.org/pyramid_storage/#configuration>`_ (default: ``default``):
.. code-block:: ini
kinto.attachment.extensions = default+video
The ``mimetypes`` option
------------------------
By default, the mimetype is guessed from the filename using Python standard mimetypes module.
If you want to add or override mimetypes, use the following setting and the associated syntax:
.. code-block:: ini
kinto.attachment.mimetypes = .ftl:application/vnd.fluent;.db:application/vnd.sqlite3
Default bucket
--------------
In order to upload files on the ``default`` bucket, the built-in default bucket
plugin should be enabled before the ``kinto_attachment`` plugin.
In the configuration, this means adding it explicitly to includes:
.. code-block:: ini
kinto.includes = kinto.plugins.default_bucket
kinto_attachment
Production
----------
* Make sure the ``base_url`` can be reached (and points to ``base_path`` if
files are stored locally)
* Adjust the max size for uploaded files (e.g. ``client_max_body_size 10m;`` for NGinx)
For example, with NGinx
::
server {
listen 80;
location /v1 {
...
}
location /files {
root /var/www/kinto;
}
}
API
===
**POST /{record-url}/attachment**
It will create the underlying record if it does not exist.
Required
- ``attachment``: a single multipart-encoded file
Optional
- ``data``: attributes to set on record (serialized JSON)
- ``permissions``: permissions to set on record (serialized JSON)
**DELETE /{record-url}/attachment**
Deletes the attachement from the record.
Attributes
----------
When a file is attached, the related record is given an ``attachment`` attribute
with the following fields:
- ``filename``: the original filename
- ``hash``: a SHA-256 hex digest
- ``location``: the URL of the attachment
- ``mimetype``: the `media type <https://en.wikipedia.org/wiki/Media_type>`_ of
the file
- ``size``: size in bytes
.. code-block:: json
{
"data": {
"attachment": {
"filename": "IMG_20150219_174559.jpg",
"hash": "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
"location": "http://cdn.service.org/files/ffa9c7b9-7561-406b-b7f9-e00ac94644ff.jpg",
"mimetype": "image/jpeg",
"size": 1481798
},
"id": "c2ce1975-0e52-4b2f-a5db-80166aeca688",
"last_modified": 1447834938251,
"theme": "orange",
"type": "wallpaper"
},
"permissions": {
"write": ["basicauth:6de355038fd943a2dc91405063b91018bb5dd97a08d1beb95713d23c2909748f"]
}
}
Usage
=====
Using HTTPie
------------
.. code-block:: bash
http --auth alice:passwd --form POST http://localhost:8888/v1/buckets/website/collections/assets/records/c2ce1975-0e52-4b2f-a5db-80166aeca689/attachment data='{"type": "wallpaper", "theme": "orange"}' "attachment@~/Pictures/background.jpg"
.. code-block:: http
HTTP/1.1 201 Created
Access-Control-Expose-Headers: Retry-After, Content-Length, Alert, Backoff
Content-Length: 209
Content-Type: application/json; charset=UTF-8
Date: Wed, 18 Nov 2015 08:22:18 GMT
Etag: "1447834938251"
Last-Modified: Wed, 18 Nov 2015 08:22:18 GMT
Location: http://localhost:8888/v1/buckets/website/collections/font/assets/c2ce1975-0e52-4b2f-a5db-80166aeca689
Server: waitress
{
"filename": "IMG_20150219_174559.jpg",
"hash": "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
"location": "http://cdn.service.org/files/ffa9c7b9-7561-406b-b7f9-e00ac94644ff.jpg",
"mimetype": "image/jpeg",
"size": 1481798
}
Using Python requests
---------------------
.. code-block:: python
auth = ("alice", "passwd")
attributes = {"type": "wallpaper", "theme": "orange"}
perms = {"read": ["system.Everyone"]}
files = [("attachment", ("background.jpg", open("Pictures/background.jpg", "rb"), "image/jpeg"))]
payload = {"data": json.dumps(attributes), "permissions": json.dumps(perms)}
response = requests.post(SERVER_URL + endpoint, data=payload, files=files, auth=auth)
response.raise_for_status()
Using JavaScript
----------------
.. code-block:: javascript
var headers = {Authorization: "Basic " + btoa("alice:passwd")};
var attributes = {"type": "wallpaper", "theme": "orange"};
var perms = {"read": ["system.Everyone"]};
// File object from input field
var file = form.elements.attachment.files[0];
// Build form data
var payload = new FormData();
// Multipart attachment
payload.append('attachment', file, "background.jpg");
// Record attributes and permissions JSON encoded
payload.append('data', JSON.stringify(attributes));
payload.append('permissions', JSON.stringify(perms));
// Post form using GlobalFetch API
var url = `${server}/buckets/${bucket}/collections/${collection}/records/${record}/attachment`;
fetch(url, {method: "POST", body: payload, headers: headers})
.then(function (result) {
console.log(result);
});
Scripts
=======
Two scripts are provided in this repository.
They rely on the ``kinto-client`` Python package, which can be installed in a
virtualenv:
::
$ virtualenv env --python=python3
$ source env/bin/activate
$ pip install kinto-client
Or globally on your system (**not recommended**):
::
$ sudo pip install kinto-client
Upload files
------------
``upload.py`` takes a list of files and posts them on the specified server,
bucket and collection::
$ python3 scripts/upload.py --server=$SERVER --bucket=$BUCKET --collection=$COLLECTION --auth "token:mysecret" README.rst pictures/*
See ``python3 scripts/upload.py --help`` for more details about options.
Download files
--------------
``download.py`` downloads the attachments from the specified server, bucket and
collection and store them on disk::
$ python3 scripts/download.py --server=$SERVER --bucket=$BUCKET --collection=$COLLECTION --auth "token:mysecret"
If the record has an ``original`` attribute, the script decompresses the attachment
after downloading it.
Files are stored in the current folder by default.
See ``python3 scripts/download.py --help`` for more details about options.
Known limitations
=================
* No support for chunk upload (#10)
* Files are not removed when server is purged with ``POST /v1/__flush__``
Relative URL in records (workaround)
------------------------------------
Currently the full URL is returned in records. This is very convenient for API consumers
which can access the attached file just using the value in the ``location`` attribute.
However, the way it is implemented has a limitation: the full URL is stored in each record
directly. This is annoying because changing the ``base_url`` setting
won't actually change the ``location`` attributes on existing records.
As workaround, it is possible to set the ``kinto.attachment.base_url`` to an empty
value. The ``location`` attribute in records will now contain a *relative* URL.
Using another setting ``kinto.attachment.extra.base_url``, it is possible to advertise
the base URL that can be preprended by clients to obtain the full attachment URL.
If specified, it is going to be exposed in the capabilities of the root URL endpoint.
Run tests
=========
Run a fake Amazon S3 server in a separate terminal::
make run-moto
Run the tests suite::
make tests
Releasing
=========
1. Create a release on Github on https://github.com/Kinto/kinto-attachment/releases/new
2. Create a new tag `X.Y.Z` (*This tag will be created from the target when you publish this release.*)
3. Generate release notes
4. Publish release
Notes
=====
* `API design discussion <https://github.com/Kinto/kinto/issues/256>`_ about mixing up ``attachment`` and record fields.
Raw data
{
"_id": null,
"home_page": null,
"name": "kinto-attachment",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "web services",
"author": null,
"author_email": "Mozilla Services <developers@kinto-storage.org>",
"download_url": "https://files.pythonhosted.org/packages/3e/f4/5b4e794236c557b98b4b1d1a2da4eebc5aec5a97b42cde9a132d2fd082f9/kinto_attachment-7.0.0.tar.gz",
"platform": null,
"description": "================\nKinto Attachment\n================\n\n.. image:: https://github.com/Kinto/kinto-attachment/actions/workflows/test.yml/badge.svg\n :target: https://github.com/Kinto/kinto-attachment/actions\n\n.. image:: https://img.shields.io/pypi/v/kinto-attachment.svg\n :target: https://pypi.python.org/pypi/kinto-attachment\n\nAttach files to `Kinto records <http://kinto.readthedocs.io>`_.\n\n\nInstall\n=======\n\n::\n\n pip install kinto-attachment\n\n\nSetup\n=====\n\nIn the Kinto project settings\n\n.. code-block:: ini\n\n kinto.includes = kinto_attachment\n kinto.attachment.base_url = http://cdn.service.org/files/\n\n\nLocal File storage\n------------------\n\nStore files locally:\n\n.. code-block:: ini\n\n kinto.attachment.base_path = /tmp\n\n\nS3 File Storage\n---------------\n\nStore on Amazon S3:\n\n.. code-block:: ini\n\n kinto.attachment.aws.access_key = <AWS access key>\n kinto.attachment.aws.secret_key = <AWS secret key>\n kinto.attachment.aws.bucket_name = <bucket name>\n kinto.attachment.aws.acl = <AWS ACL permissions|public-read>\n\n\n.. note::\n\n ``access_key`` and ``secret_key`` may be omitted when using AWS Identity\n and Access Management (IAM).\n\nSee `Pyramid Storage <https://pythonhosted.org/pyramid_storage/>`_.\n\n\nGoogle Cloud Storage\n--------------------\n\n.. code-block:: ini\n\n kinto.attachment.gcloud.credentials = <Path to the Service Accounts credentials JSON file>\n kinto.attachment.gcloud.bucket_name = <bucket name>\n kinto.attachment.gcloud.acl = publicRead\n\nSee `Google Cloud ACL permissions <https://cloud.google.com/storage/docs/access-control/making-data-public>`_\n\n\nThe ``folder`` option\n---------------------\n\nWith this option, the files will be stored in sub-folders.\n\nUse the ``{bucket_id}`` and ``{collection_id}`` placeholders to organize the files\nby bucket or collection.\n\n.. code-block:: ini\n\n kinto.attachment.folder = {bucket_id}/{collection_id}\n\nOr only for a particular bucket:\n\n.. code-block:: ini\n\n kinto.attachment.resources.blog.folder = blog-assets\n\nOr a specific collection:\n\n.. code-block:: ini\n\n kinto.attachment.resources.blog.articles.folder = articles-images\n\n\nThe ``keep_old_files`` option\n-----------------------------\n\nWhen set to ``true``, the files won't be deleted from disk/S3 when the associated record\nis deleted or when the attachment replaced.\n\n.. code-block:: ini\n\n kinto.attachment.keep_old_files = true\n\nOr only for a particular bucket:\n\n.. code-block:: ini\n\n kinto.attachment.resources.blog.keep_old_files = false\n\nOr a specific collection:\n\n.. code-block:: ini\n\n kinto.attachment.resources.blog.articles.keep_old_files = true\n\nThe ``randomize`` option\n------------------------\n\nIf you want uploaded files to be stored with a random name (default: True):\n\n.. code-block:: ini\n\n kinto.attachment.randomize = true\n\nOr only for a particular bucket:\n\n.. code-block:: ini\n\n kinto.attachment.resources.blog.randomize = true\n\nOr a specific collection:\n\n.. code-block:: ini\n\n kinto.attachment.resources.blog.articles.randomize = true\n\nThe ``extensions`` option\n-------------------------\n\nIf you want to upload files which are not in the default allowed extensions (see `Pyramid extensions groups <https://pythonhosted.org/pyramid_storage/#configuration>`_ (default: ``default``):\n\n.. code-block:: ini\n\n kinto.attachment.extensions = default+video\n\n\nThe ``mimetypes`` option\n------------------------\n\nBy default, the mimetype is guessed from the filename using Python standard mimetypes module.\n\nIf you want to add or override mimetypes, use the following setting and the associated syntax:\n\n.. code-block:: ini\n\n kinto.attachment.mimetypes = .ftl:application/vnd.fluent;.db:application/vnd.sqlite3\n\n\nDefault bucket\n--------------\n\nIn order to upload files on the ``default`` bucket, the built-in default bucket\nplugin should be enabled before the ``kinto_attachment`` plugin.\n\nIn the configuration, this means adding it explicitly to includes:\n\n.. code-block:: ini\n\n kinto.includes = kinto.plugins.default_bucket\n kinto_attachment\n\nProduction\n----------\n\n* Make sure the ``base_url`` can be reached (and points to ``base_path`` if\n files are stored locally)\n* Adjust the max size for uploaded files (e.g. ``client_max_body_size 10m;`` for NGinx)\n\nFor example, with NGinx\n\n::\n\n server {\n listen 80;\n\n location /v1 {\n ...\n }\n\n location /files {\n root /var/www/kinto;\n }\n }\n\n\nAPI\n===\n\n**POST /{record-url}/attachment**\n\nIt will create the underlying record if it does not exist.\n\nRequired\n\n- ``attachment``: a single multipart-encoded file\n\nOptional\n\n- ``data``: attributes to set on record (serialized JSON)\n- ``permissions``: permissions to set on record (serialized JSON)\n\n\n**DELETE /{record-url}/attachment**\n\nDeletes the attachement from the record.\n\n\nAttributes\n----------\n\nWhen a file is attached, the related record is given an ``attachment`` attribute\nwith the following fields:\n\n- ``filename``: the original filename\n- ``hash``: a SHA-256 hex digest\n- ``location``: the URL of the attachment\n- ``mimetype``: the `media type <https://en.wikipedia.org/wiki/Media_type>`_ of\n the file\n- ``size``: size in bytes\n\n.. code-block:: json\n\n {\n \"data\": {\n \"attachment\": {\n \"filename\": \"IMG_20150219_174559.jpg\",\n \"hash\": \"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\",\n \"location\": \"http://cdn.service.org/files/ffa9c7b9-7561-406b-b7f9-e00ac94644ff.jpg\",\n \"mimetype\": \"image/jpeg\",\n \"size\": 1481798\n },\n \"id\": \"c2ce1975-0e52-4b2f-a5db-80166aeca688\",\n \"last_modified\": 1447834938251,\n \"theme\": \"orange\",\n \"type\": \"wallpaper\"\n },\n \"permissions\": {\n \"write\": [\"basicauth:6de355038fd943a2dc91405063b91018bb5dd97a08d1beb95713d23c2909748f\"]\n }\n }\n\n\nUsage\n=====\n\nUsing HTTPie\n------------\n\n.. code-block:: bash\n\n http --auth alice:passwd --form POST http://localhost:8888/v1/buckets/website/collections/assets/records/c2ce1975-0e52-4b2f-a5db-80166aeca689/attachment data='{\"type\": \"wallpaper\", \"theme\": \"orange\"}' \"attachment@~/Pictures/background.jpg\"\n\n.. code-block:: http\n\n HTTP/1.1 201 Created\n Access-Control-Expose-Headers: Retry-After, Content-Length, Alert, Backoff\n Content-Length: 209\n Content-Type: application/json; charset=UTF-8\n Date: Wed, 18 Nov 2015 08:22:18 GMT\n Etag: \"1447834938251\"\n Last-Modified: Wed, 18 Nov 2015 08:22:18 GMT\n Location: http://localhost:8888/v1/buckets/website/collections/font/assets/c2ce1975-0e52-4b2f-a5db-80166aeca689\n Server: waitress\n\n {\n \"filename\": \"IMG_20150219_174559.jpg\",\n \"hash\": \"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad\",\n \"location\": \"http://cdn.service.org/files/ffa9c7b9-7561-406b-b7f9-e00ac94644ff.jpg\",\n \"mimetype\": \"image/jpeg\",\n \"size\": 1481798\n }\n\n\nUsing Python requests\n---------------------\n\n.. code-block:: python\n\n auth = (\"alice\", \"passwd\")\n attributes = {\"type\": \"wallpaper\", \"theme\": \"orange\"}\n perms = {\"read\": [\"system.Everyone\"]}\n\n files = [(\"attachment\", (\"background.jpg\", open(\"Pictures/background.jpg\", \"rb\"), \"image/jpeg\"))]\n\n payload = {\"data\": json.dumps(attributes), \"permissions\": json.dumps(perms)}\n response = requests.post(SERVER_URL + endpoint, data=payload, files=files, auth=auth)\n\n response.raise_for_status()\n\n\nUsing JavaScript\n----------------\n\n.. code-block:: javascript\n\n var headers = {Authorization: \"Basic \" + btoa(\"alice:passwd\")};\n var attributes = {\"type\": \"wallpaper\", \"theme\": \"orange\"};\n var perms = {\"read\": [\"system.Everyone\"]};\n\n // File object from input field\n var file = form.elements.attachment.files[0];\n\n // Build form data\n var payload = new FormData();\n // Multipart attachment\n payload.append('attachment', file, \"background.jpg\");\n // Record attributes and permissions JSON encoded\n payload.append('data', JSON.stringify(attributes));\n payload.append('permissions', JSON.stringify(perms));\n\n // Post form using GlobalFetch API\n var url = `${server}/buckets/${bucket}/collections/${collection}/records/${record}/attachment`;\n fetch(url, {method: \"POST\", body: payload, headers: headers})\n .then(function (result) {\n console.log(result);\n });\n\n\nScripts\n=======\n\nTwo scripts are provided in this repository.\n\nThey rely on the ``kinto-client`` Python package, which can be installed in a\nvirtualenv:\n\n::\n\n $ virtualenv env --python=python3\n $ source env/bin/activate\n $ pip install kinto-client\n\nOr globally on your system (**not recommended**):\n\n::\n\n $ sudo pip install kinto-client\n\n\nUpload files\n------------\n\n``upload.py`` takes a list of files and posts them on the specified server,\nbucket and collection::\n\n $ python3 scripts/upload.py --server=$SERVER --bucket=$BUCKET --collection=$COLLECTION --auth \"token:mysecret\" README.rst pictures/*\n\nSee ``python3 scripts/upload.py --help`` for more details about options.\n\n\nDownload files\n--------------\n\n``download.py`` downloads the attachments from the specified server, bucket and\ncollection and store them on disk::\n\n $ python3 scripts/download.py --server=$SERVER --bucket=$BUCKET --collection=$COLLECTION --auth \"token:mysecret\"\n\nIf the record has an ``original`` attribute, the script decompresses the attachment\nafter downloading it.\n\nFiles are stored in the current folder by default.\nSee ``python3 scripts/download.py --help`` for more details about options.\n\n\nKnown limitations\n=================\n\n* No support for chunk upload (#10)\n* Files are not removed when server is purged with ``POST /v1/__flush__``\n\nRelative URL in records (workaround)\n------------------------------------\n\nCurrently the full URL is returned in records. This is very convenient for API consumers\nwhich can access the attached file just using the value in the ``location`` attribute.\n\nHowever, the way it is implemented has a limitation: the full URL is stored in each record\ndirectly. This is annoying because changing the ``base_url`` setting\nwon't actually change the ``location`` attributes on existing records.\n\nAs workaround, it is possible to set the ``kinto.attachment.base_url`` to an empty\nvalue. The ``location`` attribute in records will now contain a *relative* URL.\n\nUsing another setting ``kinto.attachment.extra.base_url``, it is possible to advertise\nthe base URL that can be preprended by clients to obtain the full attachment URL.\nIf specified, it is going to be exposed in the capabilities of the root URL endpoint.\n\n\nRun tests\n=========\n\nRun a fake Amazon S3 server in a separate terminal::\n\n make run-moto\n\nRun the tests suite::\n\n make tests\n\n\nReleasing\n=========\n\n1. Create a release on Github on https://github.com/Kinto/kinto-attachment/releases/new\n2. Create a new tag `X.Y.Z` (*This tag will be created from the target when you publish this release.*)\n3. Generate release notes\n4. Publish release\n\n\nNotes\n=====\n\n* `API design discussion <https://github.com/Kinto/kinto/issues/256>`_ about mixing up ``attachment`` and record fields.\n",
"bugtrack_url": null,
"license": "Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. \"License\" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. \"Licensor\" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. \"Legal Entity\" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, \"control\" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. \"You\" (or \"Your\") shall mean an individual or Legal Entity exercising permissions granted by this License. \"Source\" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. \"Object\" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. \"Work\" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). \"Derivative Works\" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. \"Contribution\" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, \"submitted\" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as \"Not a Contribution.\" \"Contributor\" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a \"NOTICE\" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets \"{}\" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same \"printed page\" as the copyright notice for easier identification within third-party archives. Copyright 2016 Mozilla Foundation Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ",
"summary": "Attach files to Kinto records",
"version": "7.0.0",
"project_urls": {
"Repository": "https://github.com/Kinto/kinto-attachment"
},
"split_keywords": [
"web",
"services"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "50664b50276bdd893996a1239ec39272c7ad8e7b553a312729033cc314af3e2e",
"md5": "476524012993754cf4e0df6b231b146d",
"sha256": "32c0c000cee38b3b1e06644132ece39f24bfd55ec6a25107989b3c2828092a25"
},
"downloads": -1,
"filename": "kinto_attachment-7.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "476524012993754cf4e0df6b231b146d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 20110,
"upload_time": "2024-10-16T08:03:37",
"upload_time_iso_8601": "2024-10-16T08:03:37.391510Z",
"url": "https://files.pythonhosted.org/packages/50/66/4b50276bdd893996a1239ec39272c7ad8e7b553a312729033cc314af3e2e/kinto_attachment-7.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3ef45b4e794236c557b98b4b1d1a2da4eebc5aec5a97b42cde9a132d2fd082f9",
"md5": "0d5edbfc955cf4d936442c60daf81a53",
"sha256": "e11f8e0726ce3e1579987e9a41cb2fa41ec58356fd982367563cf80183874143"
},
"downloads": -1,
"filename": "kinto_attachment-7.0.0.tar.gz",
"has_sig": false,
"md5_digest": "0d5edbfc955cf4d936442c60daf81a53",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 63474,
"upload_time": "2024-10-16T08:03:38",
"upload_time_iso_8601": "2024-10-16T08:03:38.606682Z",
"url": "https://files.pythonhosted.org/packages/3e/f4/5b4e794236c557b98b4b1d1a2da4eebc5aec5a97b42cde9a132d2fd082f9/kinto_attachment-7.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-16 08:03:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Kinto",
"github_project": "kinto-attachment",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "kinto-attachment"
}