just for the records ...

it seems to work when filename is not defined with
response["Content-Disposition"] = "attachment; filename=äöü &%%%.pdf"
instead just use
response["Content-Disposition"] = "attachment"
and add the filename to the URL, e.g.
/user/downloads/15/äöü &%%%%.pdf
where
15 is the object-id and the filename has to be urlencoded.

within a template, it looks like this:
{% url attachment_download object.id %}{{ object.attachment.name|
urlencode }}

the view just checks if the attachment with id 15 has been uploaded by
the logged-in user and returns the attachment:

def attachment_download(request, object_id):
    import mimetypes
    obj = get_object_or_404(UserAttachment, user=request.user,
pk=object_id)
    mimetype, encoding = mimetypes.guess_type(fullpath)
    mimetype = mimetype or 'application/octet-stream'
    response = HttpResponse(obj.attachment.read(), mimetype=mimetype)
    response['Content-Length'] = obj.attachment.size
    response["Content-Disposition"] = "attachment"
    if encoding:
        response["Content-Encoding"] = encoding
    return response

tested with firefox, safari, chrome, IE7, IE8, opera ... guess it
works.

regards,
patrick


On 21 Nov., 16:31, patrickk <sehmasch...@gmail.com> wrote:
> I need to serve media-files uploaded by users, but only the user who
> uploaded a file should be able to download that file again. therefore,
> I need to check whether the currently logged-in user is the creator of
> that file (ok, that´s easy with using a view).
>
> – of course, serving the media-file via django is not an option.
> – downloading the file (changing the response-header) is not an option
> either since we need to use utf-8 filenames (same goes for xsendfile).
>
> any ideas on how to achieve this? btw, we´re using mod_wsgi.
>
> thanks,
> patrick

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

Reply via email to