Пример #1
0
def upload_image():
    image = request.json['data']
    extension = '.{}'.format(image.split(";")[0].split("/")[1])
    image_file = uploaded_image(extension=extension, file_content=image)
    force_local = request.args.get('force_local', 'false')
    if force_local == 'true':
        image_url = upload_local(
            image_file,
            UPLOAD_PATHS['temp']['image'].format(uuid=uuid.uuid4()))
    else:
        image_url = upload(
            image_file,
            UPLOAD_PATHS['temp']['image'].format(uuid=uuid.uuid4()))
    return jsonify({"url": image_url})
    def test_uploaded_image_local(self):
        """Method to test uploading image locally"""

        with app.test_request_context():
            file_content = "data:image/gif;base64,\
                            R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/\
                            fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
                            AAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7f\
                            iyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDl\
                            TImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
            uploaded_img = uploaded_image(file_content=file_content)
            file_path = uploaded_img.file_path
            actual_file_path = app.config.get('BASE_DIR') + '/static/uploads/' + uploaded_img.filename
            self.assertEqual(file_path, actual_file_path)
            self.assertTrue(os.path.exists(file_path))