我正在制作一个脚本,将来自互联网的PDF(不保存到磁盘)转换为一系列jpeg,然后将JPG保存到AWS s3。
不幸的是,下面的代码只将PDF的第一页保存为AWS。有关如何修改它以使用顺序文件名将图像保存到AWS的任何想法?
from urllib2 import urlopen
from wand.image import Image
from io import BytesIO
import boto3
s3 = boto3.client(
's3',
aws_access_key_id='mykey',
aws_secret_access_key='mykey'
)
bucket_name = 'testbucketAWS323'
#location on disk
#file prefix
test_id = 'example'
f = urlopen("https://s3.us-east-2.amazonaws.com/converted1jpgs/example.pdf")
bytes_io_file = BytesIO()
with Image(file=f) as img:
print('pages = ', len(img.sequence))
with img.convert('png') as converted:
bytes_io_file = BytesIO(converted.make_blob('jpeg'))
#code below should take 'converted' object, and save it to AWS as jpg.
s3.upload_fileobj(bytes_io_file, bucket_name, "assssd.jpg")
print 'done'
答案 0 :(得分:2)
只需枚举文档页面( if ($this->object->billing_state === 'SC') {
$this->send(
'sc@gmail.com',
$this->get_subject(),
$this->get_content(),
$this->get_headers(),
$this->get_attachments()
);
}
if ($this->object->billing_state === 'RS') {
$this->send(
'rs@gmail.com',
$this->get_subject(),
$this->get_content(),
$this->get_headers(),
$this->get_attachments()
);
}
if ($this->object->billing_state === 'PR') {
$this->send(
'pr@gmail.com',
$this->get_subject(),
$this->get_content(),
$this->get_headers(),
$this->get_attachments()
);
}
else {
$this->send(
'else@gmail.com',
$this->get_subject(),
$this->get_content(),
$this->get_headers(),
$this->get_attachments()
);
}
)即可获取页码&资源。将页面资源复制到wand.image.Image.sequence
的新实例后,直接导出blob,并且不必担心中间转换。
Image
答案 1 :(得分:1)
如何在转换时使用upload_fileobj方法?