Matt, I'd like to resize an uploaded image, while uploading i think... before it gets saved to the hard disk. How did you do it? In pre 1.0 version I redefined _save_FIELD_file from my class.
Thanks, 2008/8/14 mcordes <[EMAIL PROTECTED]>: > > Thanks Andy, > > Using the callable for upload_to is pretty interesting, but I don't > think it's usable for my purposes because I want the image file's name > to be XXX.png where XXX is the primary key for the model which, as the > documentation warns, may not be set when the upload_to callable gets > called. > > I was previously doing this in the model's save method, but as I > mentioned after the filestorage change it's not clear how to modify > the path of an existing ImageFieldFile > > As for my image processing it's pretty simple and consists of: > > 1. resize image > 2. changing format to png > 3. applying relatively simple transformations on the image > 4. then saving it in a different directory with a name based on the > model's id, something like /path/i/want/<MyModel.id>.png > > -Matt > > > On Aug 14, 12:18 am, "Andy Lei" <[EMAIL PROTECTED]> wrote: >> If the only post processing you need to do is changing the filename, you >> should pass a callable (like a function) as the upload_to parameter. >> for example: >> >> def get_upload_path(instance, filename): >> return '/path/you/want/' + instance.name >> >> class MyModel(models.Model): >> >> image = models.ImageField(upload_to=get_upload_path) >> >> Check out the documentation here: >> >> http://www.djangoproject.com/documentation/model-api/#filefield >> >> If you need to do other post processing, I think you want to take advantage >> of the pre / post save signals, or override save method on your model. Just >> do the post processing in place though; i can't see a reason why you'd need >> to save it twice. >> >> -Andy >> >> On Wed, Aug 13, 2008 at 10:22 PM, mcordes <[EMAIL PROTECTED]> wrote: >> >> > Hello, >> >> > When uploading files, I'd like to upload them to a temporary location >> > and then after post processing move them to a different directory/ >> > file. I had this working with the pre-filestorage code, but I'm not >> > sure what the correct procedure should now be. >> >> > My model looks like this: >> >> > > class MyModel(models.Model): >> > > image = models.ImageField(upload_to="images/tmp") >> >> > An uploaded file would then get stored here (relative to my media >> > root): >> >> > > images/tmp/somefile.png >> >> > I'd like to be able to modify the associated MyModel instance so its >> > image field now has a name of >> >> > > images/processed/XXX.png >> >> > I've tried using FieldFile.save as in >> >> > > myModelInstance.image.save('new/path/new.png', File(file('path to >> > processed image file'))) >> >> > and this mostly seems to work, but it throws out the 'new/path' part >> > of the name argument and my image ultimately gets stored here: >> >> > > images/tmp/new.png >> >> > rather than where I want it: 'images/processed/new.png'. >> >> > What am I missing? Am I attacking this all wrong? What are your >> > suggestions? >> >> > -Matt >> >> > > > -- Juanjo Conti --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---