So I'm keeping uploaded files in an S3 bucket. For private documents,
their S3 permissions are set to private. So my plan has been that
Django will check if a user is authenticated, and if so, pull the
document from S3 and send it to the client. I'm using the boto S3
library to do the actuall interactions with S3 (that's what all the
get_key stuff is based on below). This functions are:

@login_required
def priv_document(request, itemid):
        from myapp.media.models import Document
        import mimetypes
        d = get_object_or_404(Document, pk=itemid)
        f = get_from_s3(d.file_key)
        mtype = mimetypes.guess_type(d.file_key)
        resp = HttpResponse(f, mimetype=mtype[0])
        resp['Content-Disposition'] = 'attachment; filename=%s' %
d.file_key.split('/')[-1]
        return resp

def get_from_s3(skey):
        import tempfile
        k = get_key()
        k.key = skey
        f = tempfile.TemporaryFile(mode="wb")
        k.get_contents_to_file(f)
        f.seek(0)
        return f

However, I'm getting a corrupted file. When I did `diff origfile.pdf
downloadedfile.pdf` I found the following error inserted into the
file:

> <pre>
> Mod_python error: "PythonHandler django.core.handlers.modpython"
>
> Traceback (most recent call last):
>
>   File "/usr/lib/python2.5/site-packages/mod_python/apache.py", line 299, in 
> HandlerDispatch
>     result = object(req)
>
>   File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", 
> line 181, in handler
>     return ModPythonHandler()(req)
>
>   File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", 
> line 172, in __call__
>     for chunk in response:
>
>   File "/usr/lib/python2.5/site-packages/django/http/__init__.py", line 329, 
> in next
>     chunk = self._iterator.next()
>
> IOError: [Errno 0] Error
>
> </pre>

I thought I had found a discussion that linked this error to threading
in python - but I can't seem to find it again. Any ideas you have on
how to resolve this would be appreciated...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to