Hi,
I have the same problem as above.
I'm sure your solution works Felix, but it is important for me to
avoid resaving the files (as they can be well over 500Mb-1Gb in size).

The ideal solution would be to just change the path in the model
without having to resave the file.

Any help is appreciated.
Thanks

On Feb 3, 12:08 am, felix <crucialfe...@gmail.com> wrote:
> I was just learning/dealing with this now.
>
> example:
>
> class Mix(models.Model):
>        mp3 = models.FileField(upload_to="mixes",blank=True)
>
> # let's say the mix object already exists
> mix = Mix.objects.get( .... etc )
>
> # however you get a file
>
>         file = request.FILES[u'Filedata']
>
> # swfupload is awesome btw.
>
> or by opening it from your post processed folder somewhere
> or by creating a file directly in memory using content, or PIL etc.
>
> then the correct way is this:
>
> if mix.mp3.name: # if there is a previous file and we wish to delete it
>    mix.mp3.storage.delete( mix.mp3.name )
>
> get the field's defined storage to delete it
>
> #name will be eg. "mixes/oldfile.mp3"
>
> ideal_path = "mixes/newfile.mp3"
>
> # save the new file into storage
> saved_to = mix.mp3.storage.save( ideal_path, file )
>
> the path may have _ added to it for non-clobber purposes and is returned
> with the real path
>
> # assign the string directly to the file field input
> mix.mp3 = saved_to
>
> # and save the new path into the object
> mix.save()
>
> this is nice in that you can switch the storage later or use multiple
> storage systems across your site,
> not just
>
> from django.core.files.storage import default_storage
> default_storage.save( path, file)
>
> you can upload to "tempUploads/file.xxx" and then search for files whose
> names are still in tempUploads and thus not yet processed
>
>      felix :    crucial-systems.com
>
> On Mon, Feb 2, 2009 at 11:26 PM, timc3 <t...@timc3.com> wrote:
>
> > So I take it that there is no way of doing this?

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

Reply via email to