def uploadToImgur(deckImage, imgurId, output): imagePath = os.path.join(output, deckImage) print('Uploading file ' + deckImage + ' to Imgur!') queue.sendMessage({ 'type': 'message', 'text': 'Uploading file ' + deckImage + ' to Imgur!' }) client = ImgurClient(imgurId, '') with open(imagePath, 'rb') as imageFp: response = client.upload(imageFp) return response['link']
def create_post(user_id): datas = request.get_json() description = datas.get('description', '') if description is '': return jsonify(error="description not in JSON"), 400 title = datas.get('title', '') if title is '': return jsonify(error="title not in JSON"), 400 image = datas.get('image', '') if image is '': return jsonify(error="image not in JSON"), 400 if image.startswith("data:image/jpeg;base64,"): image = image[23:] config = { 'album': None, 'name': title, 'title': title, 'description': description } imgur_client = ImgurClient(current_app.config['IMGUR_CLIENT_ID'], current_app.config['IMGUR_CLIENT_SECRET'], current_app.config['IMGUR_ACCESS_TOKEN'], current_app.config['IMGUR_REFRESH_TOKEN']) post = Post() post.title = title post.description = description if User.query.filter(User.id.ilike(user_id)).first() is None: return jsonify(error="User inexistant"), 404 post.user_id = user_id # TODO : ajouter parallelisme image = imgur_client.upload_from_base64(image, config=config, anon=False) # on ajoute en DB l'url retourné par imgur post.url = image['link'] db.session.add(post) db.session.commit() return post_schema.jsonify(post), 200
def checkImgur(imgurId): try: client = ImgurClient(imgurId, '') except ImgurClientError: print('Imgur client information incorrect') queue.sendMessage({ 'type': 'error', 'text': 'Imgur client ID wrong. See README for details.' }) return False return True