
    ZTh<                         d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZ  G d
 de      Zy)    )Path)AnyDictOptionalUnion)urljoin)MultipartEncoder)to_json)mime_and_content_type_from_path)Entity)Metadata)SiftRestConfig_RestServicec                        e Zd ZU dZdZdZeed<   eed<   eed<   def fdZ		 	 	 dd	e
eef   d
edee   dee   dee   defdZ xZS )UploadServicez-
    Service used to upload attachments.
    z/api/v0/remote-files/uploadz /api/v0/remote-files/upload:bulk_upload_uri_upload_bulk_uri_apikey	rest_confc                     t         |   |       t        | j                  | j                        | _        t        | j                  | j                        | _        y )N)r   )super__init__r   	_base_uriUPLOAD_PATHr   UPLOAD_BULK_PATHr   )selfr   	__class__s     m/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/sift_py/file_attachment/_internal/upload.pyr   zUploadService.__init__   sE    9-"4>>43C3CD '8M8M N    pathentitymetadatadescriptionorganization_idreturnc                    t        |t              rt        |      n|}|j                         st	        d| d      t        |      \  }}}	|st	        d| d      t        |d      5 }
|j                  |j                  j                  d}|	r||
|d|	if|d<   n||
|f|d<   |rt        |      |d	<   |r||d
<   |r||d<   t        |      }| j                  j                  | j                  |d|j                  i      }|j                   dk7  r&t	        d|j                    d|j"                   d      |j%                         j'                  d      j'                  d      cd d d        S # 1 sw Y   y xY w)NzProvided path, 'z$', does not point to a regular file.zThe MIME-type of 'z' could not be computed.rb)entityId
entityTypezContent-Encodingfiler"   organizationIdr#   )fieldszContent-Type)urldataheaders   z Request failed with status code z (z).
remoteFileremoteFileId)
isinstancestrr   is_file	Exceptionr   open	entity_identity_typevaluer
   r	   _sessionpostr   content_typestatus_codereasonjsonget)r   r    r!   r"   r#   r$   
posix_path	file_namemimetypecontent_encodingr*   form_fields	form_dataresponses                 r   upload_attachmentzUploadService.upload_attachment   s    $.dC#8T$Zd
!!#.tf4XYZZ0OPZ0[-	8-0<TUVV$ ,	I",,$0066+K
  *,<	'F# (1$&AF#*1(*;J'0?,--8M*(<I }}))$$"I$:$: * H ##s*6x7K7K6LBxN__ab  ==?&&|488HY,	I ,	I ,	Is   )C:E--E6)NNN)__name__
__module____qualname____doc__r   r   r4   __annotations__r   r   r   r   r   r   r   rI   __classcell__)r   s   @r   r   r      s     0K9LO. O (,%))->ICI>I >I 8$	>I
 c]>I "#>I 
>Ir   r   N)pathlibr   typingr   r   r   r   urllib.parser   requests_toolbeltr	   sift_py._internal.convert.jsonr
   sift_py.data_import._utilsr   sift_py.file_attachment.entityr    sift_py.file_attachment.metadatar   sift_py.restr   r   r    r   r   <module>rZ      s3     - -   . 2 F 1 5 5OIL OIr   