It worked automatically for me.

Make sure you put enctype="multipart/form-data" in the form definition

http://docs.djangoproject.com/en/dev/topics/http/file-uploads/

Note that request.FILES will only contain data if the request method was
POST and the <form> that posted the request has the attribute
enctype="multipart/form-data". Otherwise, request.FILES will be empty.




Léon Dignòn wrote:
> Hello everybody,
>
> I created an upload form with the help of the docs.
> http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#topics-http-file-uploads
>
> But the handle_uploaded_file() bugs me a little bit. I set MEDIA_ROOT
> (MR) in the settings.py to an existing directory. I thought that file
> uploads work together with MR but in the docs the file is saved
> "manually" on the disk. Is there no django method which saves the file
> automatically with a given name on the disk?
>
> The result should be something like this:
> (with the file saved at MEDIA_ROOT/myfile.jpg):
>
> def def handle_uploaded_file(f):
>     f.save("myfile.jpg")
>
> Instead of:
>
> def handle_uploaded_file(f):
>     destination = open('some/file/name.txt', 'wb+')
>     for chunk in f.chunks():
>         destination.write(chunk)
>     destination.close()
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
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 
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