예제 #1
0
from flask_restful import Resource
from flask_uploads import UploadNotAllowed
from flask_jwt_extended import jwt_required, get_jwt_identity
import os
import traceback
from schemas.image import ImageSchema
from flask import request, send_file
import image_upload

imageschema = ImageSchema()


class ImageUpload(Resource):
    @jwt_required
    def post(self):

        data = imageschema.load(request.files)
        user_id = get_jwt_identity()
        image = data["image"]
        folder = f"user_{user_id}"  # static/images/user_1

        try:
            filename = image_upload.save_image(image, folder)
            basename = image_upload.get_basename(filename)
            return {
                "message":
                "The Image {} is uploaded succefully.".format(basename)
            }, 201
        except UploadNotAllowed:
            extension = image_upload.get_extension(filename)
            return {
from flask_restful import Resource
from flask_uploads import UploadNotAllowed
from flask import send_file, request
from flask_jwt_extended import jwt_required, get_jwt_identity
import traceback
import os

from libs import image_helper
from libs.strings import gettext
from schemas.image import ImageSchema

image_schema = ImageSchema()


class ImageUpload(Resource):
    @classmethod
    @jwt_required()
    def post(cls):
        """Used to upload an image file. It uses JWT to retrive user
        information and then saves the image to the user's folder. If there
        is a file name conflict, it appends a number at the end.
        """
        data = image_schema.load(request.files)
        user_id = get_jwt_identity()
        folder = f'user_{user_id}'

        try:
            image_path = image_helper.save_image(data['image'], folder=folder)
            basename = image_helper.get_basename(image_path)

            return {
예제 #3
0
from auth import AuthError, requires_auth
from flask_restful import Resource
from flask import jsonify, request, redirect
from models.recipe import RecipeModel
from schemas.recipe import RecipeSchema
from marshmallow import ValidationError
from schemas.image import ImageSchema
from flask_uploads import IMAGES, UploadSet
import json
from flask_jwt_extended import jwt_required

recipe_schemas = RecipeSchema()
image_schemas = ImageSchema()
recipe_list_schemas = RecipeSchema(many=True)

images = UploadSet("images", IMAGES)


class Recipe(Resource):
    def get(self, id):
        recipe = RecipeModel.query.filter_by(id=id).first()
        if recipe is None:
            return {
                "message": "recipe was not found",
                "success": False,
                "code": 404
            }, 404

        recipe = recipe_schemas.dump(recipe)
        recipe["ingredients"] = [{
            'name': r['name'],