ats post nginx

ats ip_allow.config  放行post请求

nginx搭建
nginx-upload-module

415 错误,因为脚本没有加上,boundary   ,
multipart/form-data; boundary=---------------------------7e42a033d209a

#!/usr/bin/python
# -*- coding: utf-8 -*-
 
import os.path
import requests
import hashlib
 
# 待上传文件路径
FILE_UPLOAD = "/opt/ats/test2.mp4"
# 上传接口地址
#UPLOAD_URL = "http://192.168.1.20:80/upload"
UPLOAD_URL = "http://zds.zcdn.net/upload/xx"
# 单个片段上传的字节数
SEGMENT_SIZE = 1048576
proxies = {'http': 'http://127.0.0.1:8081'}
def upload(fp, file_pos, size, file_size):
    session_id = get_session_id()
    fp.seek(file_pos)
    payload = fp.read(size)
 
    content_range = "bytes {file_pos}-{pos_end}/{file_size}".format(file_pos=file_pos,
                    pos_end=file_pos+size-1,file_size=file_size)
    headers = {'Content-Disposition': 'attachment; filename="big.txt"',
               'Content-Type': ' multipart/form-data; boundary=---------------------------7e42a033d209a',
                'X-Content-Range':content_range,'Session-ID': session_id,'Content-Length': size}
    res = requests.post(UPLOAD_URL, data=payload, headers=headers,proxies=proxies)
    print(res.text)
 
 
# 根据文件名hash获得session id
def get_session_id():
    m = hashlib.md5()
    file_name = os.path.basename(FILE_UPLOAD)
    m.update(file_name)
    return m.hexdigest()
 
def main():
    file_pos = 0
    file_size = os.path.getsize(FILE_UPLOAD)
    fp = open(FILE_UPLOAD,"r")
 
    while True:
        if file_pos + SEGMENT_SIZE >= file_size:
            upload(fp, file_pos, file_size - file_pos, file_size)
            fp.close()
            break
        else:
            upload(fp, file_pos, SEGMENT_SIZE, file_size)
            file_pos = file_pos + SEGMENT_SIZE
 
if __name__ == "__main__":
    main()

400错误 ,nginx 没有创建目录,error.log

11-10 02:36
查看更多