Hi Lorenzo

I suspect its not that you are uploading 2 files, but which files u
upload.

The line
print "%s %s %s %s" % (k, new_data[k]["filename"],new_data[k]["content-
type"], new_data[k]["content"])
Will print the actual content of the file you are uploading.

Now if thats an image or binary file the char \x07 will appear in it.
Which is system beep.(Printing char \x07 will make windows beep, Dell
does not play nicely with system beep, no way to mute it, I know, I
have one.)

So with many \x07 chars in the content you system is going to look
like its hanging beeping like crazy until its beeped its way through
the files you are uploading.

Caz

On Mar 18, 5:15 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi everybody,
>
> the following script running on the dev server with Py2.4/Win2k3
> (tested on both IE7 and FF2) crashes the dev server. The funny thing
> is that the files get actually written to the filesystem and CPU usage
> is normal.
>
> What i'm trying to do is allow uploading of an undeterminate number N
> of files, just as GMail does.
>
> The javascript part uses jquery.
>
> Thanks,
> Lorenzo
>
> ########template###################
> {%extends "base_template.html"%}
>
> {%block content%}
>
> <script type="text/javascript">
> function addImageField()
> {
>         var rndName = Math.ceil(Math.abs(Math.random() * 100000));
>         var chunk = "Description <input type='text' name='des" + rndName +
> "' /> <input type='file' name='img" + rndName + "' /><br />";
>
>         $("#imagefields").append(chunk);}
>
> </script>
>
> {%if error_msg%}
> <span class="error">{{error_msg}}</span>
> {%endif%}
>
> {%if info_msg%}
> <span class="info">{{info_msg}}</span>
> {%endif%}
>
> {{form.errors.as_ul}}
>
> <form action="" method="post" enctype="multipart/form-data">
>
> Description {{form.description}}
> {{form.myfile}}
>
> <br />
>
> <div id="imagefields">
>
> </div>
>
> <br />
> <a href="#" onclick="addImageField();">Attach another file</a>
> <br />
>
> <input type="submit" value="go">
>
> </form>
>
> {%endblock%}
>
> ################view###############
> class FileUploadForm(Form):
>     description = CharField(required=False)
>     myfile = CharField(widget=FileInput(), required=False)
>
> def file_upload(request):
>     if request.method == "POST":
>         new_data = request.POST.copy()
>         new_data.update(request.FILES)
>         form = FileUploadForm(new_data)
>
>         if form.is_valid():
>             for k in request.FILES.keys():
>                 print "%s %s %s %s" % (k, new_data[k]["filename"],
> new_data[k]["content-type"], new_data[k]["content"])
>                 f = file("C:\\temp\\%s" % k, "wb")
>                 try:
>                     f.write(new_data[k]["content"])
>                     f.close()
>                 except: pass
>
>             return HttpResponse("Success")
>         else:
>             context = dict(form=form, error_msg="Upload went
> bananas!")
>     else:
>         form = FileUploadForm()
>         context = dict(form=form)
>
>     return render_to_response("fileupload.html", context)


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