'For Image Upload
NB not using document_onvalidation here because we are extracting
other values from the file like size and mime type'

@staticmethod
def cap_resource_onvalidation(form):

    form_vars = form.vars
    image = form_vars.image
    if (image is None):
        encoded_file = form_vars.get('imagecrop-data', None)
        if encoded_file:
            import base64
            import uuid
            import cStringIO
            (metadata, encoded_file) = encoded_file.split(',')
            (filename, datatype, enctype) = metadata.split(';')
            f = Storage()
            f.filename = (uuid.uuid4().hex + filename)
            f.file = cStringIO.StringIO(base64.decodestring(encoded_file))
            form_vars.image = image = f
            stream = image.file
            stream.seek(0, os.SEEK_END)
            file_size = stream.tell()
            stream.seek(0)
            if (image is not None):
                (data, mime_type) = datatype.split(':')
                form_vars.size = file_size
                form_vars.mime_type = mime_type
    elif isinstance(image, str):
        return
