import json
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
file_obj = request.FILES.get("upfile")# 也可以通过读取本地文件
row = json.loads(request.POST.get('row')) #前端传回参数
file_name ='test.zip'
file_tup = (file_name, file_obj, 'application/zip')
m = MultipartEncoder(
fields={'projectId': str(row['projectId']), 'file': file_tup}
)
headers = {
'Content-Type': m.content_type,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36',
'Authorization': ‘xxxx'
}
url = 'xxxx'
res = requests.post(url, data=m, headers=headers)
resp = json.loads(res.content)
python 上传zip文件到服务器
最新推荐文章于 2024-04-23 13:36:24 发布