List Info

Thread: Why won't my file upload?




Why won't my file upload?
user name
2006-11-21 21:34:24
No matter what I do, I can't get files in this form to
upload. I've
seen:

 f = open('/path/to/output/file.jpg', 'wb') # wb = write
binary
f.write(request.FILES['photo']['content'])
f.close()

But besides not liking having the path in my view, it fails
anyway.
Says file or directory does not exist. So I've searched, and
tried
other ways, but no luck. Yes,

Here's the (short version) view:

def add_post(request, topic_slug, post_id = False):
	if request.user.is_authenticated():
		topic = Topic.objects.get(topic_slug=topic_slug)

		manipulator = Post.AddManipulator()
		if request.POST and len(request.POST.copy()['post_text'])
> 1:
			page_data = request.POST.copy()
			page_data['post_author'] = str(request.user)
                       	page_data['post_author_id'] =
request.user.id
                        post_image = ""
                        if request.FILES:
                              post_image =
request.FILES['post_image_file']['filename']

			import re
			import base64
			from datetime import datetime

			post = Post(post_topic = topic, post_text =
page_data['post_text'],
post_author = request.user, post_author_name =
request.user.get_profile().preferred_name, post_ip =
request.META['REMOTE_ADDR'], post_host =
request.META['REMOTE_HOST'],
post_image = post_image)
			post.save()

			return HttpResponseRedirect("/forum/"+
str(forum.forum_slug) + "/" +
str(topic.topic_slug) + "/" + str(topic.id) +
"/page"+ str(pmax) + "/")

So I can see the file, get it's name, and all that, but I
can't get it
to upload and save.

Here's the form:

<form method="post"
action="/forum/add_post/{}/"
id="reply"
enctype="multipart/form-data">
<label for="id_text"
class="idTextLabel">Your comment</label>
<textarea rows="10" cols="99"
name="post_text" id="id_text">{}</textarea>

<label for="post_image">Add an
Image</label>
    <input type="hidden"
id="post_image" name="post_image"
value="" />
    <input type="file"
id="id_post_image_file"
class="vImageUploadField"
name="post_image_file" />

<label for="submit"
id="submitlbl">
<input type="submit" value="{% trans
"Add Post" %}" id="submit"
/></label>
</form>


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Why won't my file upload?
user name
2006-11-22 08:54:07
Have you set correct permissions for the directory (chmod
command),
where you are moving the uploaded file?
It has to be 0775 or something similar.

Good luck!
Aidas Bendoraitis [aka Archatas]



On 11/21/06, baxtergretschpages.com <mail.baxtergmail.com> wrote:
>
> No matter what I do, I can't get files in this form to
upload. I've
> seen:
>
>  f = open('/path/to/output/file.jpg', 'wb') # wb =
write binary
> f.write(request.FILES['photo']['content'])
> f.close()
>
> But besides not liking having the path in my view, it
fails anyway.
> Says file or directory does not exist. So I've
searched, and tried
> other ways, but no luck. Yes,
>
> Here's the (short version) view:
>
> def add_post(request, topic_slug, post_id = False):
>         if request.user.is_authenticated():
>                 topic =
Topic.objects.get(topic_slug=topic_slug)
>
>                 manipulator = Post.AddManipulator()
>                 if request.POST and
len(request.POST.copy()['post_text']) > 1:
>                         page_data = request.POST.copy()
>                         page_data['post_author'] =
str(request.user)
>                         page_data['post_author_id'] =
request.user.id
>                         post_image = ""
>                         if request.FILES:
>                               post_image =
> request.FILES['post_image_file']['filename']
>
>                         import re
>                         import base64
>                         from datetime import datetime
>
>                         post = Post(post_topic = topic,
post_text = page_data['post_text'],
> post_author = request.user, post_author_name =
> request.user.get_profile().preferred_name, post_ip =
> request.META['REMOTE_ADDR'], post_host =
request.META['REMOTE_HOST'],
> post_image = post_image)
>                         post.save()
>
>                         return
HttpResponseRedirect("/forum/"+
str(forum.forum_slug) + "/" +
> str(topic.topic_slug) + "/" + str(topic.id) +
"/page"+ str(pmax) + "/")
>
> So I can see the file, get it's name, and all that, but
I can't get it
> to upload and save.
>
> Here's the form:
>
> <form method="post"
action="/forum/add_post/{}/"
> id="reply"
enctype="multipart/form-data">
> <label for="id_text"
class="idTextLabel">Your comment</label>
> <textarea rows="10" cols="99"
name="post_text" id="id_text">{{
> quote_text }}</textarea>
>
> <label for="post_image">Add an
Image</label>
>     <input type="hidden"
id="post_image" name="post_image"
value="" />
>     <input type="file"
id="id_post_image_file"
> class="vImageUploadField"
name="post_image_file" />
>
> <label for="submit"
id="submitlbl">
> <input type="submit" value="{% trans
"Add Post" %}" id="submit"
> /></label>
> </form>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Why won't my file upload?
user name
2006-11-22 18:33:38
Nope, that's not it (although I thank you for reminding me
to check
it!)... it's just not uploading the dang file!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Why won't my file upload?
user name
2006-11-22 19:21:06
Anyone? Am I not handling the form correctly? Is there
something I need
to do in my view?


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )