[英]Content-Type in for individual files in python requests
I want to request to my server running in python flask with file and some meta information.我想向在 python flask 中运行的服务器请求文件和一些元信息。 Hence my request content-Type will be 'multipart/form-data.
因此,我的请求内容类型将是“multipart/form-data”。 Is there a way i can set the content type of file like image/jpg, image/gif etc... How do i set the content-type for the file.
有没有办法设置文件的内容类型,如图像/jpg、图像/gif 等...我如何设置文件的内容类型。 Is it possible or not
有没有可能
If you make each file specification a tuple, you can specify the mime type as a third parameter:如果将每个文件规范设为元组,则可以将 MIME 类型指定为第三个参数:
files = {
'file1': ('foo.gif', open('foo.gif', 'rb'), 'image/gif'),
'file2': ('bar.png', open('bar.png', 'rb'), 'image/png'),
}
response = requests.post(url, files=files)
You can give a 4th parameter as well, which must be a dictionary with additional headers for each part.你也可以给出第四个参数,它必须是一个字典,每个部分都有额外的标题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.