@@ -351,10 +351,11 @@ async def list(
351351 async def upload_from_file (
352352 self ,
353353 file_path : str | Path ,
354- name : str | None = None ,
355354 * ,
355+ name : str | None = None ,
356356 content_type : ContentType | None = None ,
357357 metadata : Optional [Dict [str , str ]] = None ,
358+ ttl : timedelta | None = None ,
358359 ** options : Unpack [LongRequestOptions ],
359360 ) -> AsyncStorageObject :
360361 """Create and upload an object from a local file path.
@@ -381,16 +382,17 @@ async def upload_from_file(
381382
382383 name = name or path .name
383384 content_type = content_type or detect_content_type (str (file_path ))
384- obj = await self .create (name = name , content_type = content_type , metadata = metadata , ** options )
385+ ttl_ms = int (ttl .total_seconds ()) * 1000 if ttl else None
386+ obj = await self .create (name = name , content_type = content_type , metadata = metadata , ttl_ms = ttl_ms , ** options )
385387 await obj .upload_content (content )
386388 await obj .complete ()
387389 return obj
388390
389391 async def upload_from_dir (
390392 self ,
391393 dir_path : str | Path ,
392- name : str | None = None ,
393394 * ,
395+ name : str | None = None ,
394396 metadata : Optional [Dict [str , str ]] = None ,
395397 ttl : timedelta | None = None ,
396398 ** options : Unpack [LongRequestOptions ],
@@ -433,9 +435,10 @@ def synchronous_io() -> bytes:
433435 async def upload_from_text (
434436 self ,
435437 text : str ,
436- name : str ,
437438 * ,
439+ name : str ,
438440 metadata : Optional [Dict [str , str ]] = None ,
441+ ttl : timedelta | None = None ,
439442 ** options : Unpack [LongRequestOptions ],
440443 ) -> AsyncStorageObject :
441444 """Create and upload an object from a text payload.
@@ -449,7 +452,8 @@ async def upload_from_text(
449452 Returns:
450453 AsyncStorageObject: Wrapper for the uploaded object.
451454 """
452- obj = await self .create (name = name , content_type = "text" , metadata = metadata , ** options )
455+ ttl_ms = int (ttl .total_seconds ()) * 1000 if ttl else None
456+ obj = await self .create (name = name , content_type = "text" , metadata = metadata , ttl_ms = ttl_ms , ** options )
453457 await obj .upload_content (text )
454458 await obj .complete ()
455459 return obj
@@ -461,6 +465,7 @@ async def upload_from_bytes(
461465 * ,
462466 content_type : ContentType ,
463467 metadata : Optional [Dict [str , str ]] = None ,
468+ ttl : timedelta | None = None ,
464469 ** options : Unpack [LongRequestOptions ],
465470 ) -> AsyncStorageObject :
466471 """Create and upload an object from a bytes payload.
@@ -475,7 +480,8 @@ async def upload_from_bytes(
475480 Returns:
476481 AsyncStorageObject: Wrapper for the uploaded object.
477482 """
478- obj = await self .create (name = name , content_type = content_type , metadata = metadata , ** options )
483+ ttl_ms = int (ttl .total_seconds ()) * 1000 if ttl else None
484+ obj = await self .create (name = name , content_type = content_type , metadata = metadata , ttl_ms = ttl_ms , ** options )
479485 await obj .upload_content (data )
480486 await obj .complete ()
481487 return obj
0 commit comments