Coder Social home page Coder Social logo

flask-imgur's Introduction

Flask-Imgur

A simple module implementing automatic image upload into Imgur image hosting service. Imgur does have rather big and convoluted API, this library is meant for those who simply want to upload and delete images from their service with no additional hassle. Compatible with Python 2.6+ and 3.x.

For Flask-Imgur to work properly you need client id API key, see Imgur API documentation for information on how to obtain it.

client id can either be provided to your app via Flask config file (with IMGUR_ID key) or passed during Imgur class initialization

Installation

Install using pip:

pip install Flask-Imgur

Usage:

from flask import Flask
from flask_imgur import Imgur

app = Flask(__name__)
imgur_handler = Imgur(app)

Then inside a function:

@app.route("/image_upload", methods=["GET","POST"])
def get_img():
	if request.method == "POST":
		image = request.files.get("my_image")
		image_data = imgur_handler.send_image(image)

		image_data["success"] # True
		image_data["data"]["height"] # 200
		image_data["data"]["link"] # "http://imgur.com/SbBGk.jpg"
		image_data["data"]["deletehash"] # "eYZd3NNJHsbreD1"

Refer to Official model reference for info about available fields.

Another thing you might wanna do is to delete the image, this requires deletehash created when image been uploaded. Example:

	delete_info = imgur_handler.delete_image(delete_hash="eYZd3NNJHsbreD1")
	delete_info["success"] # True

Reference

send_image(image, send_params, additional_headers)

Send Werkzeug file object containing image to Imgur.

  • image (image object) -- Werkzeug image object obtained through request.files dictionary (required)
  • send_params (dict) -- Any additional data to be added to POST request (optional)
  • additional_headers (dict) -- Additional headers to be passed along with request (optional)
delete_image(delete_hash, additional_headers)

Delete the image from Imgur.

  • delete_hash (string) -- Pass deletehash obtained when sending image to Imgur
  • additional_headers (dict) -- any additional headers to be added to request

flask-imgur's People

Contributors

exaroth avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.