基于python的最简单jQuery File Upload示例
找到个很不错的文件上传插件jQuery File Upload. 资料太少. 只能自己搭个环境,照着例子摸索. 奈何最简单的例子是基于php的, 不熟. 弄了个基于python的例子.
- github
https://github.com/blueimp/jQuery-File-Upload
- 目录
使用flask做了个简单web服务器,接收上传请求. 目录结构如下
https://github.c➜ flask-demo tree . ├── app.py ├── static │ ├── 123.txt │ └── file-upload │ ├── angularjs.html │ ├── basic.html │ ├── basic-plus.html │ ├── blueimp-file-upload.jquery.json │ ├── bower.json │ ├── CONTRIBUTING.md │ ├── cors │ │ ├── postmessage.html │ │ └── result.html │ ├── css │ │ ├── demo.css │ │ ├── demo-ie8.css │ │ ├── jquery.fileupload.css │ │ ├── jquery.fileupload-noscript.css │ │ ├── jquery.fileupload-ui.css │ │ ├── jquery.fileupload-ui-noscript.css │ │ └── style.css │ ├── Gruntfile.js │ ├── img │ │ ├── loading.gif │ │ └── progressbar.gif │ ├── index.html │ ├── jquery-ui.html │ ├── js │ │ ├── app.js │ │ ├── cors │ │ │ ├── jquery.postmessage-transport.js │ │ │ └── jquery.xdr-transport.js │ │ ├── jquery.fileupload-angular.js │ │ ├── jquery.fileupload-audio.js │ │ ├── jquery.fileupload-image.js │ │ ├── jquery.fileupload-jquery-ui.js │ │ ├── jquery.fileupload.js │ │ ├── jquery.fileupload-process.js │ │ ├── jquery.fileupload-ui.js │ │ ├── jquery.fileupload-validate.js │ │ ├── jquery.fileupload-video.js │ │ ├── jquery.iframe-transport.js │ │ ├── jquery.min.js │ │ ├── main.js │ │ └── vendor │ │ └── jquery.ui.widget.js │ ├── package.json │ ├── README.md │ ├── server │ │ ├── gae-go │ │ │ ├── app │ │ │ │ └── main.go │ │ │ ├── app.yaml │ │ │ └── static │ │ │ ├── favicon.ico │ │ │ └── robots.txt │ │ ├── gae-python │ │ │ ├── app.yaml │ │ │ ├── main.py │ │ │ └── static │ │ │ ├── favicon.ico │ │ │ └── robots.txt │ │ ├── node │ │ │ ├── package.json │ │ │ ├── public │ │ │ │ └── files │ │ │ │ └── thumbnail │ │ │ ├── server.js │ │ │ └── tmp │ │ └── php │ │ ├── files │ │ ├── index.php │ │ └── UploadHandler.php │ ├── test │ │ ├── index.html │ │ └── test.js │ └── test.html └── templates └── index.html 23 directories, 57 filesom/blueimp/jQuery-File-Upload
- app.py
#encoding=utf-8 from flask import Flask from flask import request from flask import abort, redirect, url_for from flask import render_template import json app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/upload', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': f = request.files['files[]'] filename = f.filename minetype = f.content_type f.save('static/' + filename) return json.dumps({"files": [{"name": filename, "minetype": minetype}]}) if __name__ == '__main__': app.run(host="0.0.0.0", port=7000, debug=True)
- demo.html
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>jQuery File Upload 示例</title> </head> <body> <input id="fileupload" type="file" name="files[]" data-url="/upload" multiple> <script src="/static/file-upload/js/jquery.min.js"></script> <script src="/static/file-upload/js/vendor/jquery.ui.widget.js"></script> <script src="/static/file-upload/js/jquery.iframe-transport.js"></script> <script src="/static/file-upload/js/jquery.fileupload.js"></script> <script> $(function () { $('#fileupload').fileupload({ dataType: 'json', done: function (e, data) { $.each(data.result.files, function (index, file) { $('<p/>').text(file.name).appendTo(document.body); }); } }); }); </script> </body> </html>
试了之后,确实很不错.
2018年4月19日 15:39
dfdfdf
2018年7月19日 15:22
Buy a 314 Area code Phone Numbers
2018年10月08日 17:18
Thank you it important for me.
2023年8月10日 17:16
El enrutador WiFi conecta diferentes dispositivos a la interfaz de red, cualquier usuario necesita usar el nombre de usuario y la contraseña para iniciar sesión en la interfaz de credenciales del enrutador y 192.168.0.1 luego puede configurar los ajustes del enrutador, ya que generalmente la naturaleza humana olvida algo después de mucho tiempo. Entonces, cuando un usuario olvida el nombre de usuario y la contraseña de la consola de administración del enrutador, no hay necesidad de entrar en pánico y hay una solución para recuperarse.
2023年8月11日 12:48
The Printed Gujarat 7th Class Textbook 2024 are Distributed Through Cooperative Institutions All over Gujarat. Vendors are Linked to the Distribution of Textbooks with Distributors in each District. Gujarat Board Class Book 2024 are easily Accessible to All Students of This System, This will assist in improving the Quality of Teaching by Understanding the Type of Difficulties GSEB 7th Class Textbook 2024 Faced by Students of Class in Different Subjects Reading Comprehension, Mathematics and Environmental Studies. This is an effort to Provide Feedback for Planning interventions at Various Levels of School Education.
2023年8月12日 06:59
Hi everyone, I really love your story. You have very useful information; I am from Imamia Quran Academy. Online Shia Quran Institute has all the necessities for exceptional Shia Online Quran Learning. An established system of Quranic teaching and lessons with trained teaching staff greatly enhances the learning experience.
2023年9月02日 14:41
Bihar Board 1st Question Paper 2024 Available From its our website in Hindi and English Medium Pdf Format. SCERT Bihar Board Upload Examination Department usually Question Bank in Every year Month of October, Bihar Board Important Question Paper 2024 help the Students to get an idea about the Annual Exam 2020. Bihar Model Test Paper 2024 is Provided by the State Council of Educational Research SCERT Bihar 1st Class Model Paper 2024 and Training,Bihar Only,Bihar Board Model Paper 2024 have been Upload to Reveal the Exam Pattern to be Followed in SCERT Bihar Class Final Exam 2024, Bihar Class Latest Details along with Links to Download SCERT Bihar Question Paper 2024.
2023年9月25日 22:25
At Acustom Boxes, we go beyond just providing boxes. We offer various packaging options and services to meet your diverse needs.