Original path associated with an InMemoryUploadedFile

641 views
Skip to first unread message

Margie Roginski

unread,
Nov 5, 2009, 6:53:09 PM11/5/09
to Django users
In my app, my user inputs one more more attachments and on the server
side I am successfully getting them via code like this:

for file in request.FILES.getlist('attachment'):
a = Attachment(
filename = filename,
mime_type=mimetypes.guess_type(filename)[0] or
'application/octet-stream',
size=file.size,
)

In certain cases the user has errors in other parts of the form, and I
need to re-render the form. In this case I would like to re-fill the
inputs that they originally filled with the paths to their
attachments. IE, prior to submitting the form, they browsed to some
file and selected it as their attachment. When I re-render the form
after detecting an error, I would like them to not have to re-browse
to find their attachment again.

However, I do not see any way of getting the orignal path name from
the InMemoryUploadedFile that I have access to in my <file> variable.

Does anyone know if there is a way to get this original path?

Thanks!

Margie

Karen Tracey

unread,
Nov 5, 2009, 8:21:48 PM11/5/09
to django...@googlegroups.com

It doesn't matter if you are able to retrieve the original file location, the browser won't use it.  Allowing the server to pre-fill a FileInput field is considered to dangerous -- if browsers allowed this then users could be unwittingly tricked into uploading sensitive files by malicious servers. Browsers require the user to manually select a file each time one is uploaded.

Karen

Margie Roginski

unread,
Nov 6, 2009, 12:37:38 AM11/6/09
to Django users

Yeah, that makes sense. Thanks!

Margie

On Nov 5, 5:21 pm, Karen Tracey <kmtra...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages