3030from ravendb .json .metadata_as_dictionary import MetadataAsDictionary
3131from ravendb .documents .commands .batches import CommandType
3232from ravendb .documents .commands .bulkinsert import GetNextOperationIdCommand , KillOperationCommand
33+ from ravendb .documents .operations .attachments import StoreAttachmentParameters
3334from ravendb .exceptions .documents .bulkinsert import BulkInsertAbortedException
3435from ravendb .documents .identity .hilo import GenerateEntityIdOnTheClient
3536from ravendb .tools .utils import Utils
@@ -615,13 +616,16 @@ def __init__(self, operation: BulkInsertOperation, key: str):
615616 self .key = key
616617
617618 def store (self , name : str , attachment_bytes : bytes , content_type : Optional [str ] = None ) -> None :
618- self .operation ._attachments_operation .store (self .key , name , attachment_bytes , content_type )
619+ self .store_with_parameters (StoreAttachmentParameters (name , attachment_bytes , content_type = content_type ))
620+
621+ def store_with_parameters (self , parameters : StoreAttachmentParameters ) -> None :
622+ self .operation ._attachments_operation .store (self .key , parameters )
619623
620624 class AttachmentsBulkInsertOperation :
621625 def __init__ (self , operation : BulkInsertOperation ):
622626 self .operation = operation
623627
624- def store (self , key : str , name : str , attachment_bytes : bytes , content_type : Optional [ str ] = None ):
628+ def store (self , key : str , parameters : StoreAttachmentParameters ):
625629 release_lock_callback = self .operation ._concurrency_check ()
626630 try :
627631 self .operation ._end_previous_command_if_needed ()
@@ -634,22 +638,30 @@ def store(self, key: str, name: str, attachment_bytes: bytes, content_type: Opti
634638 if not self .operation ._first :
635639 self .operation ._write_comma ()
636640
641+ self .operation ._first = False
642+ self .operation ._in_progress_command = CommandType .NONE
643+
637644 self .operation ._write_string_no_escape ('{"Id":"' )
638645 self .operation ._write_string (key )
639646 self .operation ._write_string_no_escape ('","Type":"AttachmentPUT","Name":"' )
640- self .operation ._write_string (name )
647+ self .operation ._write_string (parameters . name )
641648
642- if content_type :
643- self .operation ._write_string_no_escape ('","ContentType:"' )
644- self .operation ._write_string (content_type )
649+ if parameters . content_type :
650+ self .operation ._write_string_no_escape ('","ContentType" :"' )
651+ self .operation ._write_string (parameters . content_type )
645652
646653 self .operation ._write_string_no_escape ('","ContentLength":' )
647- self .operation ._write_string_no_escape (str (len (attachment_bytes )))
654+ self .operation ._write_string_no_escape (str (len (parameters .stream )))
655+
656+ if parameters .remote_parameters is not None :
657+ self .operation ._write_string_no_escape (',"RemoteParameters":' )
658+ self .operation ._write_string_no_escape (json .dumps (parameters .remote_parameters .to_json ()))
659+
648660 self .operation ._write_string_no_escape ("}" )
649661
650662 self .operation ._flush_if_needed ()
651663
652- self .operation ._current_data_buffer += bytearray (attachment_bytes )
664+ self .operation ._current_data_buffer += bytearray (parameters . stream )
653665
654666 self .operation ._flush_if_needed ()
655667
0 commit comments