Python+;Image-使用顺序pagenumber.jpg名称将输出图像保存到AWS

Python+;Image-使用顺序pagenumber.jpg名称将输出图像保存到AWS,python,amazon-web-services,wand,Python,Amazon Web Services,Wand,我正在编写一个脚本,该脚本可以将互联网上的PDF(不保存到磁盘)转换为一系列JPEG,然后将JPG保存到AWS s3 不幸的是,下面的代码只将PDF的第一页作为JPG保存到AWS。关于如何修改它以使用顺序文件名将图像保存到AWS,有什么想法吗 from urllib2 import urlopen from wand.image import Image from io import BytesIO import boto3 s3 = boto3.client( 's3'

我正在编写一个脚本,该脚本可以将互联网上的PDF(不保存到磁盘)转换为一系列JPEG,然后将JPG保存到AWS s3

不幸的是,下面的代码只将PDF的第一页作为JPG保存到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'

在转换时使用方法如何?

在转换时使用方法如何?

只需枚举文档页面(
wand.image.image.sequence
)即可获得页码和资源。将页面资源复制到
Image
的新实例后,直接导出blob,不必担心中间转换

从urllib2导入urlopen
从wand.image导入图像
从io导入字节io
进口boto3
# ....
url='1〕https://s3.us-east-2.amazonaws.com/converted1jpgs/example.pdf'
资源=urlopen(url)
将图像(文件=资源)作为文档:
对于页码,枚举中的页码(document.sequence):
将图像(页面)作为img:
bytes\u io\u file=BytesIO(img.make\u blob('JPEG'))
文件名='output_{0}.jpg'。格式(页码)
s3.上传文件OBJ(字节文件、存储桶名称、文件名)

只需枚举文档页面(
wand.image.image.sequence
)即可获得页码和资源。将页面资源复制到
Image
的新实例后,直接导出blob,不必担心中间转换

从urllib2导入urlopen
从wand.image导入图像
从io导入字节io
进口boto3
# ....
url='1〕https://s3.us-east-2.amazonaws.com/converted1jpgs/example.pdf'
资源=urlopen(url)
将图像(文件=资源)作为文档:
对于页码,枚举中的页码(document.sequence):
将图像(页面)作为img:
bytes\u io\u file=BytesIO(img.make\u blob('JPEG'))
文件名='output_{0}.jpg'。格式(页码)
s3.上传文件OBJ(字节文件、存储桶名称、文件名)

谢谢你让我走上正轨。看来我需要先把“转换”成一个合适的对象。现在我遇到了一个不同的问题。问题更新。谢谢你让我走上正轨。看来我需要先把“转换”成一个合适的对象。现在我遇到了一个不同的问题。任务更新了。看看这个。。。看起来问题可能出在我使用字节io文件上。。。关于这个命令的一些东西只是抓取第一张图片看看这个。。。看起来问题可能出在我使用字节io文件上。。。这个命令的某些内容只是抓取第一个图像