Beispiel #1
0
    def get(self, photo_id):
        """
        Return image for thumbnail and original photo.
        :param photo_id: target photo id
        :queryparam mode: None(original) or thumbnail
        :return: image url for authenticated user
        """
        try:
            mode = request.args.get('mode')
            user = get_jwt_identity()
            email = user['email']
            path = os.path.join(app.config['UPLOAD_FOLDER'],
                                email_normalize(email))
            full_path = Path(path)
            photo = Photo.get(user['user_id'], range_key=photo_id)

            if photo.id == photo_id:
                if mode == 'thumbnail':
                    full_path = full_path / 'thumbnails' / photo.filename
                else:
                    full_path = full_path / photo.filename

            with full_path.open('rb') as f:
                contents = f.read()
                resp = make_response(contents)

            app.logger.debug('filepath: {}'.format(str(full_path)))
            resp.content_type = 'image/jpeg'
            return resp
        except Exception as e:
            app.logger.error(
                'ERROR:get photo failed:photo_id:{}'.format(photo_id))
            app.logger.error(e)
            return 'http://placehold.it/400x300'
    def get(self, photo_id):
        """
        Return image for thumbnail and original photo.
        :param photo_id: target photo id
        :queryparam mode: None(original) or thumbnail
        :return: image url for authenticated user
        """
        try:
            mode = request.args.get('mode')
            email = get_jwt_identity()['email']
            path = os.path.join(app.config['UPLOAD_FOLDER'], email_normalize(email))
            full_path = Path(path)

            photo = db.session.query(Photo).filter_by(id=photo_id).first()

            if mode == "thumbnail":
                full_path = full_path / "thumbnails" / photo.filename
            else:
                full_path = full_path / photo.filename

            with full_path.open('rb') as f:
                contents = f.read()
                resp = make_response(contents)

            app.logger.debug("filepath:{}".format(str(full_path)))
            resp.content_type = "image/jpeg"
            return resp
        except Exception as e:
            app.logger.error('ERROR:get photo failed:photo_id:{}'.format(photo_id))
            app.logger.error(e)
            return 'http://placehold.it/400x300'