Use Qiniu Cloud storage instance in PythonWeb framework Flask

Source: Internet
Author: User
This article mainly introduces the use of the Qiniu Cloud storage instance in the PythonWeb framework Flask. This article also provides an example of the use of the Qiniu Cloud storage PythonSDK. For more information about small websites, see, the free quota of Qiniu Cloud storage is sufficient to provide stable and fast storage services for the site.

Qiniu Cloud storage already has Python SDK. after simple encapsulation, it can be used directly in Flask. for the project code, see Flask-QiniuStorage on GitHub.

Sample code:

The code is as follows:


From flask import Flask
From flask_qiniustorage import Qiniu

QINIU_ACCESS_KEY = 'qiniu Access key'
QINIU_SECRET_KEY = 'qiniu Secret key'
QINIU_BUCKET_NAME = 'qiniu space name'
QINIU_BUCKET_DOMAIN = 'qiniu space domain name'

App = Flask (_ name __)
App. config. from_object (_ name __)
Qiniu_store = Qiniu (app)
# Or
# Qiniu_store = Qiniu ()
# Qiniu_store.init_app (app)

# Save the file to Qiniu
@ App. route ('/save ')
Def save ():
Data = 'data to save'
Filename = 'filename'
Ret, info = qiniu_store.save (data, filename)
Return str (ret)

# Deleting files in Qiniu space
@ App. route ('/delete ')
Def delete ():
Filename = 'filename'
Ret, info = qiniu_store.delete (filename)
Return str (ret)

# Obtain the public URL based on the file name
@ App. route ('/url ')
Def url ():
Filename = 'filename'
Return qiniu_store.url (filename)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.