I should also state that further down in the code I make use of snippets 
like:

basename = os.path.basename( instance.file.file.name )

So by not passing and uploading the file right away it seems like those 
snippets don't work anymore

On Sunday, November 24, 2013 10:31:34 AM UTC-5, Michael Manfre wrote:
>
> There are two things that you'll need to do. Set the random directory name 
> on the UpFile instance in the view and define a function to use with 
> upload_to that uses the random directory name on the instance to define the 
> file's target path.
>
>
> https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to
>
> Regards,
> Michael Manfre
>
> On Saturday, November 23, 2013 10:33:59 AM UTC-5, Matt Lind wrote:
>>
>> So I am trying to modify django-jfu ( a multi uploader) to send files to 
>> a unique directory for every unique upload session performed.  This is just 
>> due to my application's requirements and to prevent file collisions during 
>> the operations later down the road in my app.
>>
>> Anyway, here is views.py (I think the most relevant portion anyway, I 
>> could be wrong)
>>
>> def upload( request ):
>>
>>     # The assumption here is that jQuery File Upload
>>     # has been configured to send files one at a time.
>>     # If multiple files can be uploaded simulatenously,
>>     # 'file' may be a list of files.
>>     #Create the file object
>>     file = upload_receive( request )
>>
>>     #Create an instance of our Uploader Class and pass it the file object
>>     instance = UpFile ( file = file )
>>     #Save the file object
>>     instance.save() 
>>
>> And the "UpFile" class in models.py:
>>
>> class UpFile(models.Model):
>>     file = models.FileField( upload_to = 
>> MEDIA_ROOT+'/'+"".join([random.choice(string.ascii_letters) for n in 
>> xrange(12)]))
>>
>> The problem I am having is that it appears that the "random" section at 
>> the tail end of the "upload_to" option in models,py is processed only once 
>> when the server is started (or restarted).
>>
>> This won't work for my particular application, as I need the "top level" 
>> for any uploaded of a set of files to be unique.
>>
>> For example if I have the following "upload sessions"
>>
>> Session 1:  User only uploaded a single file.  A new random/unique 
>> directory should be generated under MEDIA_ROOT, and the file should be 
>> placed in that directory.
>> Session 2:  User uploaded 2 files.  A new random/unique directory should 
>> be generated under MEDIA_ROOT, and BOTH files should be uploaded to that 
>> directory (NOT a different directory per file)
>> Session 3:  User uploaded 100 files.  Like session 2 above, a new 
>> random/unique directory should be generated under MEDIA_ROOT and all 100 
>> files should be placed underneath.
>>
>> Later on I plan on cleaning house, but for now simply getting that logic 
>> down will get me moving again...
>>
>> Thanks for any help you can provide.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8170d555-94a3-4695-bff3-ab070276213f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to