Commit 7dab2ee4 authored by Julien Muchembled's avatar Julien Muchembled

shacache: fix possible MemoryError when uploaded a file

parent 9c786d3b
......@@ -27,7 +27,7 @@
##############################################################################
import hashlib
import hashlib, httplib
def WebSection_getDocumentValue(self, key, portal=None, language=None,\
......@@ -105,18 +105,18 @@ def File_viewAsWeb(self):
def WebSite_viewAsWebPost(self, *args, **kwargs):
portal = self.getPortalObject()
sha512sum = hashlib.sha512()
self.REQUEST._file.seek(0)
file = self.REQUEST._file
while True:
d = self.REQUEST._file.read(1<<20)
d = file.read(1<<20)
if not d:
break
sha512sum.update(d)
sha512sum = sha512sum.hexdigest()
document = portal.portal_contributions.newContent(data=self.REQUEST.BODY,
document = portal.portal_contributions.newContent(file=file,
filename='shacache', discover_metadata=False, reference=sha512sum,
content_type='application/octet-stream')
document.publish()
self.REQUEST.RESPONSE.setStatus(201)
self.REQUEST.RESPONSE.setStatus(httplib.CREATED)
return sha512sum
62
\ No newline at end of file
63
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment