Zope Python Script Validate file upload

if not context.REQUEST.get('photo', ''):
	state.setError('photo', 'Choose a photo to upload.')
elif context.REQUEST.get('photo', '').filename.split('.')[-1].lower() not in ['jpg','png']:
	state.setError('photo', 'Please choose a JPG or PNG')
else:
	if len(context.REQUEST.get('photo', '').read()) > 1048576:
		state.setError('photo', 'Photo size should not exceed 1MB')
		
	context.REQUEST.get('photo', '').seek(0)  # return file handle pointer to beginning
Snippet Viewed 1898 times.

Share your Zope Python Script code snippets:

  • Get some recognition & link back to your site.

 

Submit | Browse

Most Recent zope python snippets

Most Viewed