GitHub Address: Https://github.com/honmaple/maple-file
A simple image upload service with flask implementation
Design Intent
For the storage of pictures, there are many choices, general use of cloud services such as (Seven Bull, and Pat, etc.), but the domestic service like seven cattle
The custom domain name unexpectedly needs the domain name record (excuse me, originally is because the record trouble chooses the foreign country), and wasted my ten dollars,
And I imagine seven cows can be directly in the local can upload pictures, find out, did not find a more appropriate, so spend two days to write a
Use
Since the original intention is that the local script can be published, so there is no front-end interface, and so on later time, plus
Api
/api/login
/api/logout
/api/albums
/api/albums/<int:pk>
PK Album ID
/api/images
Images uploading a picture list
Album album ID (a new default album is created by defaults)
GET
Get a list of pictures
POST
Upload image
/api/images/<int:pk>
Name picture names
Description Picture Description
GET
Get picture information
PUT
Modify picture information
DELETE
Delete a picture
Configuration
Class Config (object): DEBUG = True # production environment set to false Secret_key = ' CCC ' # import Os;os.urandom ($) Secret_key_ SALT = ' ssss ' json_as_ascii = False permanent_session_lifetime = Timedelta (days=3) per_page = 10 # pagination Admin_url = '/admin/aaaaa ' # background address Login_token_header = ' Api-key ' # will affect the back headers settings Login_token = ' Api_key ' #url? api_key=21312313 middleware = [' Storage.common.middleware.CommonMiddleware '] sqlalchemy_track_ Modifications = False Sqlalchemy_database_uri = ' sqlite:///test.db ' # sqlalchemy_echo = DEBUG upload_ Allowed_extensions = set ([' PNG ', ' jpg ', ' jpeg ']) # allow upload of extension upload_folder_root = Os.path.dirname (Os.path.abspath ( file)) Upload_folder_path = ' images ' # address relative to the current file path Upload_folder = Os.path.join (Upload_folder_root, UPLOAD _folder_path)
Create an Account
Python manager.py Create_user
A default album will be created at the same time
Python manager.py key
Show user key
Upload
Image save path after uploading
Example
Use requests to upload locally
Import requestsdef images (): url = ' http://127.0.0.1:8000/api/images ' files = {' Images ': open (' desktop.png ', ' RB ')} multiple_files = [ (' Images ', (' 11.png ', open (' 11.png ', ' RB '), ' image/png ')), (' Images ', (' Desktop.png ', open (' desktop.png ', ' RB '), ' image/png ') ] headers = { ' api-key ': ' Inhpewfuzza4mddjbtx4awlppi_oxx1ki8 ', ' user-agent ': ' mozilla/5.0 (X11; Linux x86_64) applewebkit/537.36 (khtml, like Gecko) chrome/57.0.2987.98 safari/537.36 ' } # r = Requests.post ( URL, files=multiple_files, headers=headers) r = requests.post (URL, files=files, headers=headers) print ( R.text)