def upload_image_resize(request): options = {'resize': '300x300'} try: response = Image.upload(DjangoAdapter(request), '/public/', options) except Exception: response = {'error': str(sys.exc_info()[1])} return HttpResponse(json.dumps(response), content_type="application/json")
def upload_file(request): options = {'validation': None} try: response = File.upload(DjangoAdapter(request), '/public/', options) except Exception: response = {'error': str(sys.exc_info()[1])} return HttpResponse(json.dumps(response), content_type="application/json")
def upload_image_validation(request): def validation(filePath, mimetype): with wand.image.Image(filename=filePath) as img: if img.width != img.height: return False return True options = {'fieldname': 'myImage', 'validation': validation} try: response = Image.upload(DjangoAdapter(request), '/public/', options) except Exception: response = {'error': str(sys.exc_info()[1])} return HttpResponse(json.dumps(response), content_type="application/json")
def upload_file_validation(request): def validation(filePath, mimetype): size = os.path.getsize(filePath) if size > 10 * 1024 * 1024: return False return True options = {'fieldname': 'myFile', 'validation': validation} try: response = File.upload(DjangoAdapter(request), '/public/', options) except Exception: response = {'error': str(sys.exc_info()[1])} return HttpResponse(json.dumps(response), content_type="application/json")