Git Product home page Git Product logo

kinto-attachment's Introduction

kinto-attachment's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kinto-attachment's Issues

Support Kinto.js

Any way to make this work with Kinto.JS Sync? It would be nice if I could attach the file offline in Kinto.JS, then have it extracted to S3 on the server during synch.

AttributeError: 'NoneType' object has no attribute 'file'

kinto-attachment 0.7.1, messing around with the API from js, managed to crash the server with some rotten request:

ERROR:kinto.core.views.errors:"POST  /v1/buckets/custom/collections/plop/records/2f3473f9-8259-4cb3-9ec7-121d151e1a4f/attachment" ? (? ms) 'NoneType' object has no attribute 'file' agent=node-fetch/1.0 (+https://github.com/bitinn/node-fetch) authn_type=basicauth collection_id=record collection_timestamp=1468484695624 errno=110 exception=Traceback (most recent call last):
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/tweens.py", line 22, in excview_tween
    response = handler(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 101, in tm_tween
    reraise(*exc_info)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/compat.py", line 15, in reraise
    raise value
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 83, in tm_tween
    response = handler(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/router.py", line 158, in handle_request
    view_name
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/view.py", line 547, in _call_view
    response = view_callable(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/config/views.py", line 182, in __call__
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 393, in attr_view
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 371, in predicate_wrapper
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 302, in _secured_view
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 442, in rendered_view
    result = view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
    response = view(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/cornice/service.py", line 573, in wrapper
    response = view_(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto_attachment/views/services.py", line 19, in attachment_post
    return post_attachment_view(request, SINGLE_FILE_FIELD)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto_attachment/views/__init__.py", line 34, in post_attachment_view
    gzipped=gzipped)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto_attachment/utils.py", line 126, in save_file
    content.file.seek(0)
AttributeError: 'NoneType' object has no attribute 'file' lang=None uid=a9d81e1b56f2b77103e87601621a99b3d82a15abf7c72ce57a032d0964317c7a

I unfortunately can't provide a curl/httpie command for reproducing as fetch doesn't expose such a feature.

Add pattern in download path

Currently, every attachment of every collections are stored in the same folder.

It would be nice to be able to specify something like:

kinto.attachment.base_path = /tmp/{collection_id}

or

kinto.attachment.aws.bucket = {bucket-id}-{collection-id}

Concurrency headers

  • Fail if provided ETag does not match existing record
  • Fail with If-None-Match if record already exists

Add a requirements file for scripts

The kinto-attachment/setup.py is responsible of dependencies of the plugin. However scripts have one dependency which is kinto-client we should add a requirements file there to help executing the scripts.

Switch to after commit events

Currently when a delete request is rolledback, the attachment file is deleted.
The new AfterResourceChanged allows to register subscribers that are executed if and only if the commit was done and successful.

For example, in order to delete files from filestorage:

  • Use ResourceChanged events to mark file links as «deleted»
  • Use AfterResourceChanged events to delete files that have file links marked as deleted

Crash with Kinto 5.3

I'm curious to see how we didn't catch this in kinto-dist integration tests...

Support sending attachments without filename

Use case: from kinto-http.js, being able to attach a file coming from a dataURI (without filename).

def save_file(content, request, randomize=True, gzipped=False):
    folder_pattern = request.registry.settings.get('attachment.folder', '')
    folder = folder_pattern.format(**request.matchdict) or None

    # Read file to compute hash.
    if not isinstance(content, cgi.FieldStorage):
        error_msg = 'Filename is required.'
        raise_invalid(request, location='body', description=error_msg)

__init__() takes 2 positional arguments but 3 were given

Setting up kinto-attachment 0.7.0 locally against Kinto 3.2.1, Ubuntu 16.05, Python 3.5.1 (standard dist package).

kinto.ini:

[app:main]
use = egg:kinto

# Required by integration tests
kinto.flush_endpoint_enabled = true

# Required by basic auth
kinto.userid_hmac_secret = a-secret-string

# Allow browsing all buckets
kinto.bucket_read_principals = system.Authenticated

# Plugins registration
kinto.includes = kinto.plugins.default_bucket
                 kinto_attachment

# Kinto-attachment
kinto.attachment.base_url = http://cdn.service.org/files/
kinto.attachment.folder = {bucket_id}/{collection_id}
kinto.attachment.keep_old_files = true
kinto.attachment.base_path = /tmp

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 8888

The server starts fine:

$ .venv/bin/kinto --ini test/kinto.ini start
Starting server in PID 7954.
serving on http://0.0.0.0:8888

But requesting GET http://0.0.0.0:8888/v1/buckets/custom/collections/plop/records/96a38b32-2bf2-47a2-9ddc-944965ebd6dd/attachment explodes with:

ERROR:kinto.core.views.errors:"GET   /v1/buckets/custom/collections/plop/records/96a38b32-2bf2-47a2-9ddc-944965ebd6dd/attachment" ? (? ms) __init__() takes 2 positional arguments but 3 were given agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 authn_type=None errno=None exception=Traceback (most recent call last):
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/tweens.py", line 22, in excview_tween
    response = handler(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 101, in tm_tween
    reraise(*exc_info)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/compat.py", line 15, in reraise
    raise value
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 83, in tm_tween
    response = handler(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/router.py", line 127, in handle_request
    root = root_factory(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto_attachment/utils.py", line 32, in __init__
    resource = Record(request, self)
TypeError: __init__() takes 2 positional arguments but 3 were given lang=fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4 uid=None

What am I doing wrong? Edit: I know this GET request is not supported, though I was not expecting it to raise.

Decide if the file hash should be hex digest or base64 digest.

The doc said the latter but the code implements the former.

Should we let it like it is implemented or change it to use a base64 digest?

The usage is that people are using hexdigest for shasum. In cryptography we are using base64. Matter of taste I supposed.

Error when using local storage

Here is an extract of my config file:

kinto.includes = kinto.plugins.default_bucket
                 kinto_attachment

kinto.attachment.base_path = /tmp
kinto.attachment.base_url = http://localhost/
kinto.attachment.folder = {bucket_id}/{collection_id}
kinto.attachment.keep_old_files = true

I posted an attachment after creating the corresponding collections:

http --auth bob:passwd --form POST http://localhost:8888/v1/buckets/default/collections/pictures/records/de5c7f0a-ea9a-466f-ba36-6e69f76155bd/attachment "attachment@~/Pictures/Firefox-Nebula-Background.jpg"

As a result I got a error 500:

HTTP/1.1 500 Internal Server Error
Access-Control-Expose-Headers: Backoff,Retry-After,Alert,Content-Length
Content-Length: 196
Content-Type: application/json; charset=UTF-8
Date: Tue, 08 Mar 2016 16:50:21 GMT
Server: waitress

{
    "code": 500,
    "errno": 999,
    "error": "Internal Server Error",
    "info": "https://github.com/mozilla-services/cliquet/issues/",
    "message": "A programmatic error occured, developers have been informed."
}

On the server, I got this error:

2016-03-08 17:50:21,353 ERROR [venusian][waitress] "POST  /v1/buckets/57465e3f-bbb8-58d0-7190-465e69faa967/collections/pictures/records/de5c7f0a-ea9a-466f-ba36-6e69f76155bd/attachment" ? (? ms) You can only set Request.body to bytes (not <class 'str'>) agent=HTTPie/0.9.3; collection_timestamp=1457455821327; authn_type=BasicAuth; collection_id=record; uid=d693e011c88aeb3c6e28ad0b95e73120e007687d81f7e3d7ec3204eaa2c3e8ab; lang=None; errno=110; exception=Traceback (most recent call last):
[stacktrace]
TypeError: You can only set Request.body to bytes (not <class 'str'>)
2016-03-08 17:50:21,354 INFO  [venusian][waitress] "POST  /v1/buckets/57465e3f-bbb8-58d0-7190-465e69faa967/collections/pictures/records/de5c7f0a-ea9a-466f-ba36-6e69f76155bd/attachment" 500 (31 ms) request.summary time=2016-03-08T17:50:21.354000; agent=HTTPie/0.9.3; collection_timestamp=1457455821327; authn_type=BasicAuth; collection_id=record; uid=d693e011c88aeb3c6e28ad0b95e73120e007687d81f7e3d7ec3204eaa2c3e8ab; lang=None; errno=999

But the attachment is stored in /tmp/57465e3f-bbb8-58d0-7190-465e69faa967/pictures/f5044403-6314-4b63-b52e-2f93a721fd8b.jpg.

Could you help me understand what is wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.