diff --git a/bt5/erp5_web_shacache/ExtensionTemplateItem/ShaCache.py b/bt5/erp5_web_shacache/ExtensionTemplateItem/ShaCache.py index 683de974c62fe8c2ddd9dae18e38d69971eb5540..17cce302599b15598f9a37ba4ca7bb550ad667e3 100644 --- a/bt5/erp5_web_shacache/ExtensionTemplateItem/ShaCache.py +++ b/bt5/erp5_web_shacache/ExtensionTemplateItem/ShaCache.py @@ -107,3 +107,43 @@ def WebSection_putFactory(self, name, typ, body): .WebSite_publishDocumentByActivity() return document + + +def File_viewAsWeb(self): + """ + Make possible to send the file data to the client without consume the + RAM memory. + """ + RESPONSE = self.REQUEST.RESPONSE + RESPONSE.setHeader('Content-Type', self.getContentType()) + RESPONSE.setHeader('Content-Length', self.getSize()) + RESPONSE.setHeader('Accept-Ranges', 'bytes') + + # If the file is not a Pdata, we should return the data directly. + data=self.data + if isinstance(data, str): + RESPONSE.setBase(None) + return data + + # Once the object is PData type, + # we must iterate and send chunk by chunk. + while data is not None: + # Break!! If the channel is closed. + # if the client side stops the connection brutally + # the server side should stop. + if RESPONSE.stdout._channel.closed: + break + # Send data to the client. + RESPONSE.write(data.data) + + # Load next object. + next_data = data.next + + # Desactivate the object, make sure that this object content + # is not loaded in RAM memory. + data._p_deactivate() + + # Set the new data. + data=next_data + + return '' diff --git a/bt5/erp5_web_shacache/SkinTemplateItem/portal_skins/erp5_web_shacache/File_viewAsWeb.xml b/bt5/erp5_web_shacache/SkinTemplateItem/portal_skins/erp5_web_shacache/File_viewAsWeb.xml new file mode 100644 index 0000000000000000000000000000000000000000..185e22c12e5a87af02b6ef9e5ed62aef411383c3 --- /dev/null +++ b/bt5/erp5_web_shacache/SkinTemplateItem/portal_skins/erp5_web_shacache/File_viewAsWeb.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_function</string> </key> + <value> <string>File_viewAsWeb</string> </value> + </item> + <item> + <key> <string>_module</string> </key> + <value> <string>ShaCache</string> </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>File_viewAsWeb</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_web_shacache/bt/revision b/bt5/erp5_web_shacache/bt/revision index 7d37386284a97324cbac474cb5ea5360d361d104..abc4eff6ac83026669840d289fce80cc9a42baaa 100644 --- a/bt5/erp5_web_shacache/bt/revision +++ b/bt5/erp5_web_shacache/bt/revision @@ -1 +1 @@ -45 \ No newline at end of file +46 \ No newline at end of file