我试图在Flask应用程序中在浏览器中返回PDF。我使用AWS S3存储文件,使用boto3作为SDK与S3进行交互。到目前为止我的代码是:
s3 = boto3.resource('s3', aws_access_key_id=settings.AWS_ACCESS_KEY,
aws_secret_access_key=settings.AWS_SECRET_KEY)
file = s3.Object(settings.S3_BUCKET_NAME, 'test.pdf')).get()
response = make_response(file)
response.headers['Content-Type'] = 'application/pdf'
return response
我能够使用boto3成功从file
中的S3中检索对象,但是这是一个我不确定如何从该字典中返回PDF的字典
答案 0 :(得分:4)
事实证明boto3没有read()
方法,但它们确实有response = make_response(file['Body'].read())
response.headers['Content-Type'] = 'application/pdf'
return response
方法,所以它可以通过以下方式工作:
SELECT orderID, scheduling_type, frm_lang, to_lang, customer_id, amount,
onsite_con_phone, assg_frm_date, assg_frm_st, timezone FROM
`order_onsite_interpreter` WHERE scheduling_type IN ('conference_call',
'get_call') AND push_notification_sent =0 AND is_phone =1 AND
DATE_SUB(CONVERT_TZ(DATE_FORMAT(FROM_UNIXTIME(assg_frm_timestamp), '%Y-%c-%d
%T:%f'), '-7:00', '-0:00'),INTERVAL 5 MINUTE) BETWEEN CONVERT_TZ(DATE_SUB(NOW(),
INTERVAL 5 MINUTE), '-7:00', '-0:00') AND CONVERT_TZ(NOW(), '-7:00', '-0:00')