Rename uploaded files

2009-07-20 Thread Aurélien APTEL

Hi,

I'm uploading images (represented by a FileField) and I need to rename
those files when they are uploaded.
I want them to be formated like that "%d-%d-%s.%s" % (width, height,
md5hash, original_extension)
I've read the documentation and I think a need to write my own
FileSystemStorage class but how can I get the md5 hash and the image
resolution if the file isn't saved yet ?

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



Re: How to rename uploaded files in FileField?

2008-11-03 Thread bovine

thank u very much!, I think that can solve my problem.

On 11月4日, 上午12时38分, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> On Mon, Nov 3, 2008 at 11:04 AM, Chen Yinliu <[EMAIL PROTECTED]> wrote:
> > I've searched this group and find some related mails, but their solutions
> > seem out of date, for example:
> >http://gulopine.gamemusic.org/2007/nov/07/customizing-filenames-witho...
> > but there is no _save_FIELD_file method there, the underline file storage
> > system had been refactored in 1.0 release.
>
> > so anyone who know how to do it? thanks very much.
>
> You might consider the new documentation on the subject,[1] which
> should (I hope) be quite clear.
>
> -Gul
>
> [1]http://docs.djangoproject.com/en/dev/ref/models/fields/#filefield
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: How to rename uploaded files in FileField?

2008-11-03 Thread Marty Alchin

On Mon, Nov 3, 2008 at 11:04 AM, Chen Yinliu <[EMAIL PROTECTED]> wrote:
> I've searched this group and find some related mails, but their solutions
> seem out of date, for example:
> http://gulopine.gamemusic.org/2007/nov/07/customizing-filenames-without-patching/
> but there is no _save_FIELD_file method there, the underline file storage
> system had been refactored in 1.0 release.
>
> so anyone who know how to do it? thanks very much.

You might consider the new documentation on the subject,[1] which
should (I hope) be quite clear.

-Gul

[1] http://docs.djangoproject.com/en/dev/ref/models/fields/#filefield

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



How to rename uploaded files in FileField?

2008-11-03 Thread Chen Yinliu
I've searched this group and find some related mails, but their solutions
seem out of date, for example:
http://gulopine.gamemusic.org/2007/nov/07/customizing-filenames-without-patching/
but there is no _save_FIELD_file method there, the underline file storage
system had been refactored in 1.0 release.

so anyone who know how to do it? thanks very much.



-- 
Chen Yingliu

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



Re: How can I rename uploaded files to a random filename?

2007-06-27 Thread Vincent Nijs
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" <[EMAIL PROTECTED]> wrote:

> 
> On 6/25/07, rob <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How can I rename uploaded files to a random filename?

2007-06-26 Thread Russell Keith-Magee

On 6/25/07, rob <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How can I rename uploaded files to a random filename?

2007-06-24 Thread rob

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?

Thanks.


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