Add media content type inference and path-based upload methods for images and documents
This commit is contained in:
parent
937cd86c8b
commit
6d54c5900c
4 changed files with 202 additions and 16 deletions
|
|
@ -22,11 +22,7 @@ def build_client() -> EbayClient:
|
|||
|
||||
|
||||
def upload_image_from_file(client: EbayClient, image_path: Path) -> None:
|
||||
image = client.media.create_image_from_file(
|
||||
file_name=image_path.name,
|
||||
content=image_path.read_bytes(),
|
||||
content_type="image/jpeg",
|
||||
)
|
||||
image = client.media.create_image_from_path(image_path)
|
||||
print("image_url:", image.imageUrl)
|
||||
|
||||
|
||||
|
|
@ -49,15 +45,22 @@ def upload_document_and_wait(client: EbayClient, document_path: Path) -> None:
|
|||
print("document_final_status:", accepted.documentStatus)
|
||||
|
||||
|
||||
def upload_video_and_wait(client: EbayClient, video_path: Path) -> None:
|
||||
live_video = client.media.create_upload_and_wait_video(
|
||||
CreateVideoRequest(
|
||||
title=video_path.stem,
|
||||
size=video_path.stat().st_size,
|
||||
classification=["ITEM"],
|
||||
description="Example upload from the ebay-rest-client workspace.",
|
||||
def upload_document_and_wait_from_path(client: EbayClient, document_path: Path) -> None:
|
||||
accepted = client.media.create_upload_and_wait_document_from_path(
|
||||
CreateDocumentRequest(
|
||||
documentType="USER_GUIDE_OR_MANUAL",
|
||||
languages=["en-US"],
|
||||
),
|
||||
content=video_path.read_bytes(),
|
||||
document_path,
|
||||
timeout_seconds=60.0,
|
||||
)
|
||||
print("document_final_status:", accepted.documentStatus)
|
||||
|
||||
|
||||
def upload_video_and_wait(client: EbayClient, video_path: Path) -> None:
|
||||
live_video = client.media.create_upload_and_wait_video_from_path(
|
||||
video_path,
|
||||
description="Example upload from the ebay-rest-client workspace.",
|
||||
timeout_seconds=120.0,
|
||||
)
|
||||
print("video_status:", live_video.status)
|
||||
|
|
@ -77,7 +80,7 @@ def main() -> None:
|
|||
if image_url:
|
||||
upload_image_from_url(client, image_url)
|
||||
if document_file:
|
||||
upload_document_and_wait(client, Path(document_file))
|
||||
upload_document_and_wait_from_path(client, Path(document_file))
|
||||
if video_file:
|
||||
upload_video_and_wait(client, Path(video_file))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue