【发布时间】:2022-11-19 00:17:20
【问题描述】:
我已经构建了一个将 PDF 作为输入的 streamlit 应用程序。一切完成后,我想将初始 pdf 文件保存/上传到 s3 存储桶以供将来检查。
st.markdown =('# Imdocker pull mysql/mysql-server:latestport your PDF file')
pdf = st.file_uploader(label='Drag the PDF file here. Limit 100MB')
if pdf is not None:
text = TextExtraction.extract_text(pdf)
bluh bluh 脚本对 pdf 没有任何作用。
最后我有:
s3 = boto3.resource(
service_name='s3',
region_name='ams3',
aws_access_key_id='5LVOTUJBAAJ2IIMGVBJV',
aws_secret_access_key='4SwvDZyDCbcmxoup6BPLImYc4aSeWuGLKECRTdgIn0Y',
)
bucket_name = 'mirai-pdf-private-stage'
print(pdf)
print(type(pdf))
pdf.seek(0)
name = 'pdf_' + str(id) + '.pdf'
print(name)
s3.Bucket(bucket_name).upload_fileobj(pdf, 'pdf_storage', name)
得到错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 563, in _run_script
exec(code, module.__dict__)
File "/app/main.py", line 124, in <module>
s3.Bucket(bucket_name).upload_fileobj(pdf, 'pdf_storage', name)
File "/usr/local/lib/python3.9/site-packages/boto3/s3/inject.py", line 678, in bucket_upload_fileobj
return self.meta.client.upload_fileobj(
File "/usr/local/lib/python3.9/site-packages/boto3/s3/inject.py", line 629, in upload_fileobj
future = manager.upload(
File "/usr/local/lib/python3.9/site-packages/s3transfer/manager.py", line 321, in upload
self._validate_all_known_args(extra_args, self.ALLOWED_UPLOAD_ARGS)
File "/usr/local/lib/python3.9/site-packages/s3transfer/manager.py", line 500, in _validate_all_known_args
raise ValueError(
ValueError: Invalid extra_args key 'p', must be one of: ACL, CacheControl, ChecksumAlgorithm, ContentDisposition, ContentEncoding, ContentLanguage, ContentType, ExpectedBucketOwner, Expires, GrantFullControl, GrantRead, GrantReadACP, GrantWriteACP, Metadata, ObjectLockLegalHoldStatus, ObjectLockMode, ObjectLockRetainUntilDate, RequestPayer, ServerSideEncryption, StorageClass, SSECustomerAlgorithm, SSECustomerKey, SSECustomerKeyMD5, SSEKMSKeyId, SSEKMSEncryptionContext, Tagging, WebsiteRedirectLocation
我在网上找不到任何类似或解决我的问题的东西。
我试着改变:
s3.Bucket(bucket_name).upload_fileobj(pdf, 'pdf_storage', name)
至
s3.Bucket(bucket_name).upload_fileobj(pdf, 'pdf_storage', name, extra_arg=None)
并得到意外的参数错误。
提前致谢!
【问题讨论】:
标签: python pdf amazon-s3 streamlit