Re: FileField and moving or updating files
Thanks for the information, its much appreciated. Currently we are not doing anything that special. We use Nginx as our webserver, with the configuration set to receive large files, then django is then sent the file and we are just using the standard method of multiple_chunks() . Everything on Nginx and django seems to cope really well, but the big pain comes from the web browsers themselves. Most seem to try and load the file in to memory before uploading. This causes a lot of problems. --~--~-~--~~~---~--~~ 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: FileField and moving or updating files
and btw. if you have any wisdom regarding uploading really large files then please share ! I posted another thread on that. On Tue, Feb 3, 2009 at 8:50 PM, felix wrote: > > oh if its already where you want it (as long as its in the MEDIA ROOT) > then just set the file field with the string: > > obj.filefield = "path/to/file.mov" > obj.save() > > > I might be wrong on this, but : > if you are working with a File that has a path, then you aren't really > moving it. > say its in /tmp/87fac12 > and you > obj.filefield.storage.save( newpath,file ) > > it moves the file on the filesystem (gives it a new path reference), but it > doesn't have to actually move anything really. > its actually "rename" > > the filesystem itself is a kind of database and you are just assigning a > new path > > look at django.core.files.move > > > felix :crucial-systems.com > > > > On Tue, Feb 3, 2009 at 8:24 PM, azimix79 wrote: > >> >> 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 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 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 -~--~~~~--~~--~--~---
Re: FileField and moving or updating files
oh if its already where you want it (as long as its in the MEDIA ROOT) then just set the file field with the string: obj.filefield = "path/to/file.mov" obj.save() I might be wrong on this, but : if you are working with a File that has a path, then you aren't really moving it. say its in /tmp/87fac12 and you obj.filefield.storage.save( newpath,file ) it moves the file on the filesystem (gives it a new path reference), but it doesn't have to actually move anything really. its actually "rename" the filesystem itself is a kind of database and you are just assigning a new path look at django.core.files.move felix :crucial-systems.com On Tue, Feb 3, 2009 at 8:24 PM, azimix79 wrote: > > 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 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 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 -~--~~~~--~~--~--~---
Re: FileField and moving or updating files
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 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 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 -~--~~~~--~~--~--~---
Re: FileField and moving or updating files
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 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 -~--~~~~--~~--~--~---
Re: FileField and moving or updating files
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 -~--~~~~--~~--~--~---