@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)
                
                # extract mime_type
                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):
            # Image = String => Update not a create, so file not in form
            return

    # -------------------------------------------------------------------------
For Image Upload
dataset/ETHPy150Open sahana/eden/modules/s3db/cap.py/S3CAPModel.cap_resource_onvalidation