def create_upload_image(clt, imageType, imageExt): request = CreateUploadImageRequest.CreateUploadImageRequest() request.set_ImageType(imageType) request.set_ImageExt(imageExt) request.set_accept_format('JSON') return json.loads(clt.do_action_with_exception(request)) try: clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>') imageInfo = create_upload_image(clt, 'cover', 'jpg') print(json.dumps(imageInfo, ensure_ascii=False, indent=4)) except Exception as e: print(e) print(traceback.format_exc())
def __createUploadImage(self, uploadImageRequest): request = CreateUploadImageRequest.CreateUploadImageRequest() request.set_ImageType(uploadImageRequest.imageType) # 图片用途(必填) request.set_ImageExt(uploadImageRequest.imageExt) # 图片扩展名(可选,默认png) if uploadImageRequest.title: title = AliyunVodUtils.subString(uploadImageRequest.title, VOD_MAX_TITLE_LENGTH) request.set_Title(title) # 图片标题(可选参数) if uploadImageRequest.tags: request.set_Tags(uploadImageRequest.tags) # 图片标签,多个用逗号分隔(可选) request.set_accept_format('JSON') result = json.loads(self.__vodClient.do_action_with_exception(request).decode('utf-8')) result['UploadAddress'] = json.loads(base64.b64decode(result['UploadAddress']).decode('utf-8')) result['UploadAuth'] = json.loads(base64.b64decode(result['UploadAuth']).decode('utf-8')) logger.info("CreateUploadImage, FilePath: %s, ImageId: %s, ImageUrl: %s" % ( uploadImageRequest.filePath, result['ImageId'], result['ImageURL'])) return result