On Mar 29, 8:22 am, bruno desthuilliers <bruno.desthuilli...@gmail.com> wrote: > On 19 mar, 20:05,pjmorse<flashesofpa...@gmail.com> wrote: > > > In my application's admin console, there's a tiny form for updating > > the image associated with a specific model. > > > When a file is uploaded, the application reaches this code: > > > if request.method == 'POST': > > file = request.FILES.copy() > > Err... Do you really need this line ??? I don't know what your > remaining code (the one you didn't show) is doing exactly, but as far > as i'm concerned, I never needed to try & copy request.FILES...
That's a good question, and one I hadn't been prepared to answer; I didn't write this code, I just try to maintain it. The next steps in the code are to manipulate the file name. Trying to do this directly on request.FILES results in the error, "'InMemoryUploadedFile' object is unsubscriptable". Here's a wider chunk of the code. I've reformatted the comments to make things a bit more compact. if request.method == 'POST': file = request.FILES.copy() # Handle profile image upload if 'image' in file: # Profile image has been submitted img = file['image'] # Compute filename lst = split( img['filename'] ) random.seed() filename = 'wmm_%d%s' % ( random.randrange(1,10000000000000,2),str( splitext( lst[1] )[1] )) open('/tmp/' + filename, 'wb').write(img['content']) I think this tells me that what I need to figure out is how to safely copy an InMemoryUploadedFile object. pjm -- 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.