180M电子书

通过已经下载到pc,在上传到私有公网服务器,之后,再异地下载

以下代码,文件内容错乱

[root@bigdata-server- mydataweb]# tree
.
├── mydl.py
└── templates
├── hello.html
└── 计算机网络第六版.pdf directory, files
[root@bigdata-server- mydataweb]# cat mydl.py
from flask import Flask, render_template myapp = Flask(__name__) @myapp.route('/hello/<name>')
def hello(name=None):
return render_template('hello.html', name=name) if __name__ == '__main__':
myapp.run(host='0.0.0.0', debug=True)
[root@bigdata-server- mydataweb]# cat templates/hello.html
<!doctype html>
<title>Hello from Flask</title>
{% if name %}
<h1>Hello {{ name }}!</h1>
{% else %}
<h1>Hello, World!</h1>
{% endif %} <a href="./计算机网络第六版.pdf" download="计算机网络第六版.pdf">Download file</a>
[root@bigdata-server- mydataweb]#

[root@bigdata-server-03 mydataweb]# du -Bm
87M ./templates
87M .
[root@bigdata-server-03 mydataweb]# du -Bm
87M ./templates
87M .
[root@bigdata-server-03 mydataweb]# du -Bk
89288K ./templates
89296K .
[root@bigdata-server-03 mydataweb]# du -Bk
89464K ./templates
89472K .
[root@bigdata-server-03 mydataweb]#

sftp

浏览器显示的文件地址为

http://ip:5000/hello/file

局域网测试时: http://192.168.2.51:5000/hello/a.txt

待优化方向:

在不要求公网ip的情况下,走局域网快速传输到手机

以下代码,测试了4K txt文件

from flask import Flask, send_from_directory

myapp = Flask(__name__)

@myapp.route('/hello/<name>')
def hello(name=None):
if name == 'cisco':
return send_from_directory('./', 'f.txt', as_attachment=True) if __name__ == '__main__':
myapp.run(host='0.0.0.0', debug=True)

180M pdf文件未测试

服务脚本

from flask import Flask, send_from_directory

myapp = Flask(__name__)

@myapp.route('/myfile/<uid>')
def myfile(uid=None):
f = '{}logo.jpg'.format(uid)
return send_from_directory('./myfile/', f, as_attachment=True) @myapp.route('/mycode/<imgname>')
def mycode(imgname=None):
f = imgname
return send_from_directory('./mycode/', f, as_attachment=True) if __name__ == '__main__':
myapp.run(host='0.0.0.0', debug=True)

文件下载

import requests

url = 'http://192.168.6.22:5000/hello/cisco'
url = 'http://192.168.6.22:5000/myfile/34054505' def dl_webimg(img_path, img_url, img_name):
try:
# ONLY
if requests.get(img_url).status_code == :
bytes = requests.get(img_url)._content
if bytes != :
r = '{}{}'.format(img_path, img_name)
with open(r, 'wb')as f:
f.write(bytes)
return True
except Exception as e:
logs = e
print(logs)
return False
192.168.3.103 - - [16/May/2018 19:38:44] "GET /myfile/34062376 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:38:49] "GET /myfile/50011457 HTTP/1.1" 404 -
192.168.2.157 - - [16/May/2018 19:38:54] "GET /myfile/50008187 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:38:54] "GET /myfile/50008187 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:39:32] "GET /myfile/50004237 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:40:36] "GET /myfile/50005924 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:40:36] "GET /myfile/50005924 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:40:39] "GET /myfile/50011844 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:41:23] "GET /myfile/33999180 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:41:23] "GET /myfile/33999180 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:41:27] "GET /myfile/33985565 HTTP/1.1" 404 -
192.168.2.157 - - [16/May/2018 19:41:28] "GET /myfile/50006768 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:41:28] "GET /myfile/50006768 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:41:31] "GET /myfile/50012105 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:41:48] "GET /myfile/34059578 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:41:48] "GET /myfile/34059578 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:41:56] "GET /myfile/50011842 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:41:57] "GET /myfile/50011596 HTTP/1.1" 404 -
192.168.2.40 - - [16/May/2018 19:42:26] "GET /myfile/34046392 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:42:26] "GET /myfile/34046392 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:42:40] "GET /myfile/50010681 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:42:40] "GET /myfile/50010681 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:42:40] "GET /myfile/34005188 HTTP/1.1" 404 -
192.168.2.40 - - [16/May/2018 19:42:42] "GET /myfile/50009318 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:42:49] "GET /myfile/34057076 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:42:49] "GET /myfile/34057076 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:42:57] "GET /myfile/50010796 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:42:57] "GET /myfile/50010796 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:42:57] "GET /myfile/50011625 HTTP/1.1" 404 -
192.168.2.157 - - [16/May/2018 19:43:05] "GET /myfile/34064430 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:43:05] "GET /myfile/34064430 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:43:07] "GET /myfile/34034844 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:43:07] "GET /myfile/34034844 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:43:11] "GET /myfile/33996397 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:43:11] "GET /myfile/33996397 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:43:20] "GET /myfile/50011577 HTTP/1.1" 404 -
192.168.2.40 - - [16/May/2018 19:43:25] "GET /myfile/50006165 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:43:56] "GET /myfile/34061589 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:43:56] "GET /myfile/34061589 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:44:03] "GET /myfile/34015391 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:44:07] "GET /myfile/50007988 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:07] "GET /myfile/50007988 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:44:10] "GET /myfile/50001587 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:44:10] "GET /myfile/50001587 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:14] "GET /myfile/50005155 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:14] "GET /myfile/50005155 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:19] "GET /myfile/50010215 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:44:20] "GET /myfile/50010215 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:44:23] "GET /myfile/50005051 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:44:27] "GET /myfile/50011528 HTTP/1.1" 404 -
192.168.2.40 - - [16/May/2018 19:44:43] "GET /myfile/34031512 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:44:43] "GET /myfile/34031512 HTTP/1.1" 200 -
192.168.2.40 - - [16/May/2018 19:44:52] "GET /myfile/50002485 HTTP/1.1" 404 -
192.168.2.157 - - [16/May/2018 19:44:55] "GET /myfile/50000148 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:44:55] "GET /myfile/50000148 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:44:57] "GET /myfile/34015601 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:45:02] "GET /myfile/34030027 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:02] "GET /myfile/34030027 HTTP/1.1" 200 -
192.168.2.157 - - [16/May/2018 19:45:05] "GET /myfile/50009356 HTTP/1.1" 404 -
192.168.3.102 - - [16/May/2018 19:45:12] "GET /myfile/34064430 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:12] "GET /myfile/34064430 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:19] "GET /myfile/50007083 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:19] "GET /myfile/50007083 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:22] "GET /myfile/50009027 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:22] "GET /myfile/50009027 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:27] "GET /myfile/34021924 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:27] "GET /myfile/34021924 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:31] "GET /myfile/50003822 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:31] "GET /myfile/50003822 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:38] "GET /myfile/50007274 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:38] "GET /myfile/50007274 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:45:41] "GET /myfile/34064093 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:45:41] "GET /myfile/34064093 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:41] "GET /myfile/34063466 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:41] "GET /myfile/34063466 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:45:45] "GET /myfile/50007149 HTTP/1.1" 200 -
192.168.3.103 - - [16/May/2018 19:45:45] "GET /myfile/50007149 HTTP/1.1" 200 -
192.168.3.102 - - [16/May/2018 19:45:48] "GET /myfile/34004441 HTTP/1.1" 404 -
192.168.3.103 - - [16/May/2018 19:45:51] "GET /myfile/34063434 HTTP/1.1" 200 -

  

flask笔记:14:获取所有post或者get请求参数 - CSDN博客 https://blog.csdn.net/u013055678/article/details/70214756

函数修饰符

python中的@ - 半天的半天 - 博客园 https://www.cnblogs.com/mxh1099/p/5685619.html

flask 文件下载 文件服务器 请求参数 函数修饰符的更多相关文章

  1. Python中的函数修饰符@

    首先,什么是函数修饰符?函数修饰符就是对原有函数做一层包装.比如有以下两个函数: 复制代码 def func1(): print 'I am function func1' def func2(): ...

  2. python函数修饰符@的使用

    python函数修饰符@的作用是为现有函数增加额外的功能,常用于插入日志.性能测试.事务处理等等. 创建函数修饰符的规则:(1)修饰符是一个函数(2)修饰符取被修饰函数为参数(3)修饰符返回一个新函数 ...

  3. Python 函数修饰符(装饰器)的使用

     Python 函数修饰符(装饰器)的使用 1.  修饰符的来源修饰符是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的有插入日志.性能测试.事务处理等. 修饰符是解决这类问题的绝佳设计, ...

  4. solidity 学习笔记(3) 函数修饰符/继承

    修饰符: 函数修饰符有 constant  view pure 其中 constant和view的功能是一样的  不会消耗gas 也就是说不会做任何存储   constant在5.0以后的版本中被废弃 ...

  5. Flask基础(09)-->请求勾子函数

    什么是请求勾子? 为了让每个视图函数避免编写重复的功能代码,flask提供了通用设施的功能,就是所谓的勾子 那么请求勾子就是,在浏览器请求服务器资源的前后挂载相关的处理函数 请求勾子有什么作用? 作用 ...

  6. (三)flask中的请求钩子函数

    请求勾子 在客户端和服务器交互的过程中,有些准备工作或扫尾工作需要处理,比如: 在请求开始时,建立数据库连接: 在请求开始时,根据需求进行权限校验: 在请求结束时,指定数据的交互格式: 为了让每个视图 ...

  7. ethereum(以太坊)(十)--函数修饰符

    pragma solidity ^0.4.0; contract modifierTest{ uint public v1; uint constant v2 =10; //uint constant ...

  8. Java中的public、private、protected,函数修饰符

    1.public:public表明该数据成员.成员函数是对所有用户开放的,项目中其他脚本都可以直接进行调用 2.private:private表示私有,私有的意思就是除了脚本之外,项目中其他类都不可以 ...

  9. Python 中的@修饰符作用

    在Python 2.4以上的的函数中偶尔会看到函数定义的上一行有@functionName的修饰,这一下这个语法细节,其实这有点像C语言带参数的宏操作,解释器读到这样的修饰之后,会先解析@后的内容,直 ...

随机推荐

  1. 学习PyQuery库

    学习PyQuery库 好了,又是学习的时光啦,今天学习pyquery 来进行网页解析 常规导入模块(PyQuery库中的pyquery类) from pyquery import PyQuery as ...

  2. linux进程按启动时间排序命令

    show me the code... ps aux --sort=start_time|grep Full|grep -v grep

  3. Auto-Scaling Web Applications in Clouds: A Taxonomy and Survey读书笔记

    这篇文章是发在2018年CSUR上的一篇文章,主要是讲虚拟机上web应用的auto-scaling技术的分类 近年来许多web 应用服务商将他们的应用迁移到云数据中心,为什么要迁移到云上呢?其中一个重 ...

  4. bzoj2277 [Poi2011]Strongbox

    2277: [Poi2011]Strongbox Time Limit: 60 Sec  Memory Limit: 32 MBSubmit: 498  Solved: 218[Submit][Sta ...

  5. 转载:K-means聚类算法

    转载地址:http://www.cnblogs.com/jerrylead/archive/2011/04/06/2006910.html K-means也是聚类算法中最简单的一种了,但是里面包含的思 ...

  6. bzoj 3223 文艺平衡树 splay 区间翻转

    Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 17715  Solved: 7769[Submit][Status][ ...

  7. hdu1059(背包dp二进制优化)

    Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  8. 【LibreOJ10121】与众不同(RMQ,二分)

    题意: 思路: C++ #include<map> #include<set> #include<cmath> #include<cstdio> #in ...

  9. 【ZJOI2017 Round1练习&BZOJ4765】D1T3 普通计算姬(主席树,分块)

    题意: 思路:分块 使用树状数组维护sum[i]的前缀和 使用主席树维护root到u的路径上点的编号出现的个数 每次操作如果是修改就加入队列 如果是询问,考虑块内操作对询问的影响,每次在x点加上y会使 ...

  10. jquery serializeArray() 方法通过序列化表单值来创建对象数组(名称和值)。

    serializeArray() 方法序列化表单元素(类似 .serialize() 方法),返回 JSON 数据结构数据. html代码: <form> <div><i ...