python 远端url转成文本对象上传AWS

上传文件到AWS 及其他资源池
def
upload_initial_avatar(recruiter, image_object): try: file_path = recruiter.avatar_dir_path(image_object.name.split("/")[-1]) image_object.seek(0) object = s3_put_object(file_path, image_object, "image/png") recruiter._avatar = "https://{}/{}".format(object.bucket_name, object.key) file_name = "jobseeker-{}-avatar-{}-{}".format( recruiter.id, int(time.time()), image_object.name ) image_object.seek(0) response = upload_im_attachment(image_object, file_name) if response != {}: recruiter.avatar_tmm = response["im_object_id"] recruiter.save() return recruiter except Exception as e: capture_exception(e) raise e

 

#远端url转成f 文件对象
import io
from urllib.request import urlopen, Request

def url_to_obj():
    request = Request(
            url=image_url,
            headers={"User-Agent": "Mozilla/5.0"}
        )
        image_data = urlopen(request).read()
        f = io.BytesIO(image_data)
        upload_avatar(recruiter, f, f"{recruiter.id}.png", "image/png")

 

posted @ 2023-01-12 21:28  Οo白麒麟оΟ  阅读(49)  评论(2编辑  收藏  举报