Changeset 6525 for main/waeup.sirp/trunk
- Timestamp:
- 15 Jul 2011, 10:56:53 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/image/README.txt
r6310 r6525 33 33 'test data' 34 34 35 Tramline Support 36 ---------------- 37 35 38 The WAeUPImageFile object normally stores the file data using ZODB 36 persistence. For better efficiency, each file is stored in a Blob. 37 `ImageFile` field 39 persistence. Files can however also be stored by tramline. If 40 tramline is installed in Apache, the Tramline takes care of generating 41 ids for files and storing the file on the filesystem directly. The ids 42 are then passed as file data to be stored in the ZODB. 43 44 Let's first enable tramline. 45 46 The tramline directory structure is a directory with two subdirectories, 47 one called 'repository' and the other called 'upload':: 48 49 >>> import tempfile, os 50 >>> dirpath = tempfile.mkdtemp() 51 >>> repositorypath = os.path.join(dirpath, 'repository') 52 >>> uploadpath = os.path.join(dirpath, 'upload') 53 >>> os.mkdir(repositorypath) 54 >>> os.mkdir(uploadpath) 55 56 We create a TramlineFileRetrieval object knowing about this directory, 57 and register it as a utility:: 58 59 >>> from hurry.file.file import TramlineFileRetrievalBase 60 >>> class TramlineFileRetrieval(TramlineFileRetrievalBase): 61 ... def getTramlinePath(self): 62 ... return dirpath 63 >>> retrieval = TramlineFileRetrieval() 64 >>> component.provideUtility(retrieval, IFileRetrieval) 65 66 Now let's store a file the way tramline would during upload:: 67 68 >>> f = open(os.path.join(repositorypath, '1'), 'wb') 69 >>> f.write('test data') 70 >>> f.close() 71 72 The file with underlying name '1' (the data stored in the ZODB will be 73 just '1') will now be created:: 74 75 >>> file = WAeUPImageFile('foo.jpg', '1') 76 77 The data is now '1', referring to the real file:: 78 79 >>> file.data 80 '1' 81 82 Retrieving the file results in the real file:: 83 84 >>> f = file.file 85 >>> f.read() 86 'test data' 87 88 We can also retrieve its size:: 89 90 >>> file.size 91 9L 92 93 Now let's disable tramline in our utility:: 94 95 >>> class TramlineFileRetrieval(TramlineFileRetrievalBase): 96 ... def getTramlinePath(self): 97 ... return dirpath 98 ... def isTramlineEnabled(self): 99 ... return False 100 >>> component.provideUtility(TramlineFileRetrieval(), IFileRetrieval) 101 102 We expect the same behavior as when tramline is not installed:: 103 104 >>> file = WAeUPImageFile('foo.jpg', 'data') 105 >>> f = file.file 106 >>> f.read() 107 'data' 108 >>> file.size 109 4 110 111 Support for :mod:`waeup.sirp.imagestorage` 112 ------------------------------------------ 113 114 The behaviour shown above can be used for any Zope3 application. With 115 :mod:`waeup.sirp` we use a special file retrieval utility defined in 116 :mod:`waeup.sirp.imagestorage`. As this utility is based on 117 :mod:`waeup.sirp` internal stuff we do not show it here but in the 118 tests that come with that storage type. 119 120 Put roughly, an imagestorage stores file data in containers of blobs 121 belonging to a certain site. See the module itself for details. 122 123 `ImageFile` Field 38 124 ----------------- 39 125
Note: See TracChangeset for help on using the changeset viewer.