是的,我们可以使用 Python 的 requests 库和 boto3 库将 multipart/form-data 请求的 application/pdf 部分直接写入 AWS S3 存储桶。下面是示例代码:
import requests
import boto3
# 获取 multipart/form-data 请求的 application/pdf 部分数据
url = 'https://example.com/form'
response = requests.get(url)
pdf_data = response.content
# 将 pdf_data 写入 AWS S3 存储桶
bucket_name = 'my-bucket'
object_key = 'example.pdf'
session = boto3.Session()
s3 = session.resource('s3')
bucket = s3.Bucket(bucket_name)
bucket.put_object(Key=object_key, Body=pdf_data)
print('PDF 上传成功!')
以上代码假设我们从名为 https://example.com/form 的 URL 中获取 PDF 数据,并将其写入名为 my-bucket 的 AWS S3 存储桶中的 example.pdf 对象中。如果 PDF 数据已存在于本地文件中,则可以使用 open 函数打开该文件并从中读取数据,然后将其传递给 put_object 方法。