@@ -2610,6 +2610,7 @@ def upload(
26102610 field_name : Optional [str ] = None ,
26112611 display_name : Optional [str ] = None ,
26122612 tag_list : Optional [str ] = None ,
2613+ created_at : Optional [datetime .datetime ] = None ,
26132614 ) -> int :
26142615 """
26152616 Upload a file to the specified entity.
@@ -2634,6 +2635,8 @@ def upload(
26342635 This field must be a File/Link field type.
26352636 :param str display_name: The display name to use for the file. Defaults to the file name.
26362637 :param str tag_list: comma-separated string of tags to assign to the file.
2638+ :param datetime.datetime created_at: Optional datetime value to set as the created_at
2639+ time for the Attachment entity. If ``None``, the server will use the current time.
26372640 :returns: Id of the Attachment entity that was created for the image.
26382641 :rtype: int
26392642 :raises: :class:`ShotgunError` on upload failure.
@@ -2662,6 +2665,12 @@ def upload(
26622665 if os .path .getsize (path ) == 0 :
26632666 raise ShotgunError ("Path cannot be an empty file: '%s'" % path )
26642667
2668+ if created_at is not None :
2669+ if not isinstance (created_at , datetime .datetime ):
2670+ raise ShotgunError (
2671+ "created_at must be a datetime.datetime instance, got '%s'" % type (created_at )
2672+ )
2673+
26652674 is_thumbnail = field_name in [
26662675 "thumb_image" ,
26672676 "filmstrip_thumb_image" ,
@@ -2679,6 +2688,7 @@ def upload(
26792688 display_name ,
26802689 tag_list ,
26812690 is_thumbnail ,
2691+ created_at ,
26822692 )
26832693 else :
26842694 return self ._upload_to_sg (
@@ -2689,6 +2699,7 @@ def upload(
26892699 display_name ,
26902700 tag_list ,
26912701 is_thumbnail ,
2702+ created_at ,
26922703 )
26932704
26942705 def _upload_to_storage (
@@ -2700,6 +2711,7 @@ def _upload_to_storage(
27002711 display_name : Optional [str ],
27012712 tag_list : Optional [str ],
27022713 is_thumbnail : bool ,
2714+ created_at : Optional [datetime .datetime ] = None ,
27032715 ) -> int :
27042716 """
27052717 Internal function to upload a file to the Cloud storage and link it to the specified entity.
@@ -2712,6 +2724,7 @@ def _upload_to_storage(
27122724 :param str display_name: The display name to use for the file. Defaults to the file name.
27132725 :param str tag_list: comma-separated string of tags to assign to the file.
27142726 :param bool is_thumbnail: indicates if the attachment is a thumbnail.
2727+ :param datetime created_at: The datetime to set for the attachment.
27152728 :returns: Id of the Attachment entity that was created for the image.
27162729 :rtype: int
27172730 """
@@ -2768,6 +2781,8 @@ def _upload_to_storage(
27682781 # None gets converted to a string and added as a tag...
27692782 if tag_list :
27702783 params ["tag_list" ] = tag_list
2784+ if created_at is not None :
2785+ params ["created_at" ] = created_at
27712786
27722787 result = self ._send_form (url , params )
27732788 if not result .startswith ("1" ):
@@ -2790,6 +2805,7 @@ def _upload_to_sg(
27902805 display_name : Optional [str ],
27912806 tag_list : Optional [str ],
27922807 is_thumbnail : bool ,
2808+ created_at : Optional [datetime .datetime ] = None ,
27932809 ) -> int :
27942810 """
27952811 Internal function to upload a file to Shotgun and link it to the specified entity.
@@ -2848,6 +2864,8 @@ def _upload_to_sg(
28482864 # None gets converted to a string and added as a tag...
28492865 if tag_list :
28502866 params ["tag_list" ] = tag_list
2867+ if created_at is not None :
2868+ params ["created_at" ] = created_at
28512869
28522870 params ["file" ] = open (path , "rb" )
28532871
@@ -4852,4 +4870,4 @@ def _optimize_filter_field(
48524870 elif recursive and isinstance (field_value , list ):
48534871 return [_optimize_filter_field (fv , recursive = False ) for fv in field_value ]
48544872
4855- return field_value
4873+ return field_value
0 commit comments