#10300: Custom File Storage Backend broken by recent SVN commit.
-------------------------------------------+--------------------------------
          Reporter:  erikcw                |         Owner:  nobody             
   
            Status:  new                   |     Milestone:  1.1                
   
         Component:  File uploads/storage  |       Version:  SVN                
   
        Resolution:                        |      Keywords:  file upload 
storage s3
             Stage:  Accepted              |     Has_patch:  0                  
   
        Needs_docs:  0                     |   Needs_tests:  0                  
   
Needs_better_patch:  0                     |  
-------------------------------------------+--------------------------------
Comment (by kmtracey):

 Replying to [comment:4 erikcw]:
 > I've attached a copy of the Modified storage backend (S3Storage.py) in
 case it will help in tracking this issue down.

 Yes, I think it helps.  Your S3Storage _put_file function looks like this:

 {{{
 #!python
     def _put_file(self, name, content):
         if self.encrypt == True:

             # Create a key object
             k = ezPyCrypto.key()

             # Read in a public key
             fd = open(settings.CRYPTO_KEYS_PUB, "rb")
             pubkey = fd.read()
             fd.close()

             # import this public key
             k.importKey(pubkey)

             # Now encrypt some text against this public key
             content = k.encString(content)

             # ...snip remainder...
 }}}

 looking at the ezPyCrypto code, that encString(content) call is going to
 result in it doing a len(content) to get the length of the data to
 encrypt.  Given what I detailed above, that len call is going to result in
 the storage backend being called to report the length of something that
 hasn't been written to the backend yet.

 I've attached a patch that may fix the issue.  It changes the !FieldFile's
 _get_size method so that the storage backend is called to supply the
 length only if _committed is true.  If not, super is used to fallback to
 File's size property, which will be the size of the uploaded file.  That
 may be all that's needed to fix this -- could you give it a try an let us
 know?

 Review from someone more familiar with this code would be good.  I'm still
 vaguely worried about he side-effects on method resolution order
 introduced by r9766, but that could be due to my relative unfamiliarity
 with the code here.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10300#comment:6>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to