开发者

how to add http header to a pdf file using python?

开发者 https://www.devze.com 2023-03-20 06:05 出处:网络
Hi is it possible to add a http header to a pdf file like Content-Disposition:attachment;filename=test.pdf in python, for 开发者_开发技巧now what i do is i send my pdf files to Amazons S3 by adding

Hi is it possible to add a http header to a pdf file like Content-Disposition:attachment;filename=test.pdf in python, for 开发者_开发技巧now what i do is i send my pdf files to Amazons S3 by adding

--add-header=Content-Disposition:attachment;filename=test.pdf

but i would like to set this in python


Do you mean you want to upload files to S3 using Python and set some extra headers along the way?

If so, you could use simples3 library. Or some other similar library. I'll cover using simples3:

Follow the docs on how to instantiate a S3Bucket object. Once you have that, you can do:

bucket.put('path/to/your/pdf/object/on/s3',
           pdf_object_bytes,
           headers={'Content-Disposition': 'attachment;filename=test.pdf'})


Tried writing to a file or parsing everything as a string?

0

精彩评论

暂无评论...
验证码 换一张
取 消