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")
每天逼着自己写点东西,终有一天会为自己的变化感动的。这是一个潜移默化的过程,每天坚持编编故事,自己不知不觉就会拥有故事人物的特质的。 Explicit is better than implicit.(清楚优于含糊)