推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
Concise
V2EX  ›  Python

requests 发送 formdata 表单如何提交 FileStorage 数据

  •  
  •   Concise · Dec 26, 2019 · 4130 views
    This topic created in 2468 days ago, the information mentioned may be changed or developed.
    前端用表单给我发来一个文件 然后我需要再将这个文件用表单提交给另外一个地址
    我拿到这个文件数据后发现是 FileStorage 类型 当我准备直接拿去提交的时候突然想到以往表单提交都是用 open 打开本地文件的方式 这下我就懵逼了 难道我只能先写出到本地然后在 open 后提交 这样是不是太蠢了... 有没有直接转换的方法呀
    todd7zhang
        1
    todd7zhang  
       Dec 26, 2019
    只要你的 FileStorage 有 read 的实现,那就直接传就行了
    requests.post(url, files={'f_name': open('tmp.file', 'r')})
    requests.post(url, files={'f_name': file_storage_instance})
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1364 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 16:43 · PVG 00:43 · LAX 09:43 · JFK 12:43
    ♥ Do have faith in what you're doing.