|
List Info
Thread: Re: How can I rename uploaded files to a random filename?
|
|
| Re: How can I rename uploaded files to a
random filename? |

|
2007-06-26 22:43:13 |
On 6/25/07, rob <rob rawb.net> wrote:
>
> We upload all of our images via the Admin app and would
like all
> uploaded images to be renamed to a set of numbers. We
can generate the
> random numbers fine, but is there an easy way to rename
the file once
> it's uploaded in the Admin app?
Not at present. You would need to write a customized
FileField to
implement this sort of behaviour.
Yours,
Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: How can I rename uploaded files to a
random filename? |
  United States |
2007-06-27 01:51:27 |
|
If you just want to upload some files you might do something like the following. The save function uses plain python to save the files to the FILE_UPLOAD_DIR you defined in your setting file. You can play around with the file names as much as you want here.
Question: Why a random name?
Vincent
class Application_files(forms.Form):
cv = forms.Field(label = 'CV *', widget = forms.FileInput(), help_text="pdf or Word document")
paper = forms.Field(label = 'Paper *', widget = forms.FileInput(), help_text="pdf or Word document")
def save(file,key,user,ext,overwrite=True):
if ext in ['pdf','doc']:
f = open('%s%s_%s.%s' % (settings.FILE_UPLOAD_DIR,key,user,ext,),'wb')
f.write(file)
f.close()
def apply(request):
if request.POST:
for i in request.FILES.keys():
ext = request.FILES[i]['filename'][-3:].lower()
file = request.FILES[i]['content']
save(file,i,request.user,ext.lower())
else:
form = Application_files()
return render_to_response('apply/apply.html',{'form':form,})
On 6/26/07 10:43 PM, "Russell Keith-Magee" <freakboy3742 gmail.com> wrote:
>
> On 6/25/07, rob <rob rawb.net> wrote:
>>
>> We upload all of our images via the Admin app and would like all
>> uploaded images to be renamed to a set of numbers. We can generate the
>> random numbers fine, but is there an easy way to rename the file once
>> it's uploaded in the Admin app?
>
> Not at present. You would need to write a customized FileField to
> implement this sort of behaviour.
>
> Yours,
> Russ Magee %-)
>
> >
--
Vincent R. Nijs
Assistant Professor of Marketing
Kellogg School of Management, Northwestern University
2001 Sheridan Road, Evanston, IL 60208-2001
Phone: +1-847-491-4574 Fax: +1-847-491-2498
E-mail: v-nijs kellogg.northwestern.edu
Skype: vincentnijs
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---
|
[1-2]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|