filelib/client.py
def __prep_file_to_upload(self, file):
        """
        Read file, if parm is string into memory for upload
        Or read the file-like object from memory for upload.
        https://2.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file
        :param file: str -> Path to the file that will be uploaded.

        :return:[
                (FORM_FIELD_FILE_NAME, open('path_to_file/pyfile-1.pdf', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/test', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/10mb.jpg', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/nasa2.jpg', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/nasa3.tif', 'rb')),
            ]
        """
        if type(file) is str:
            content = open(file, 'rb')
            file_name = content.name
        else:
            content = file.read()
            file_name = file.name
        file_name = os.path.basename(file_name)
        if not file_name:
            file_name = str(uuid4())
        request_file_object = [(FORM_FIELD_FILE_NAME, (file_name, content))]
        return request_file_object

        Read file, if parm is string into memory for upload
        Or read the file-like object from memory for upload.
        https://2.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file
        :param file: str -> Path to the file that will be uploaded.

        :return:[
                (FORM_FIELD_FILE_NAME, open('path_to_file/pyfile-1.pdf', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/test', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/10mb.jpg', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/nasa2.jpg', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/nasa3.tif', 'rb')),
            ]
        
Read file, if parm is string into memory for upload
Or read the file-like object from memory for upload.
Read file if parm is string into memory for upload Or read the file - like object from memory for upload .
def __prep_file_to_upload(self, file):
        if type(file) is str:
            content = open(file, 'rb')
            file_name = content.name
        else:
            content = file.read()
            file_name = file.name
        file_name = os.path.basename(file_name)
        if not file_name:
            file_name = str(uuid4())
        request_file_object = [(FORM_FIELD_FILE_NAME, (file_name, content))]
        return request_file_object
def __prep_file_to_upload ( self , file ) : if type ( file ) is str : content = open ( file , 'rb' ) file_name = content . name else : content = file . read ( ) file_name = file . name file_name = os . path . basename ( file_name ) if not file_name : file_name = str ( uuid4 ( ) ) request_file_object = [ ( FORM_FIELD_FILE_NAME , ( file_name , content ) ) ] return request_file_object
Read file, if parm is string into memory for upload
Or read the file-like object from memory for upload.
Read file if parm is string into memory for upload Or read the file - like object from memory for upload .
"""
        Read file, if parm is string into memory for upload
        Or read the file-like object from memory for upload.
        https://2.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file
        :param file: str -> Path to the file that will be uploaded.

        :return:[
                (FORM_FIELD_FILE_NAME, open('path_to_file/pyfile-1.pdf', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/test', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/10mb.jpg', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/nasa2.jpg', 'rb')),
                (FORM_FIELD_FILE_NAME, open('path_to_file/nasa3.tif', 'rb')),
            ]
        """
[
(FORM_FIELD_FILE_NAME, open('path_to_file/pyfile-1.pdf', 'rb')),
(FORM_FIELD_FILE_NAME, open('path_to_file/test', 'rb')),
(FORM_FIELD_FILE_NAME, open('path_to_file/10mb.jpg', 'rb')),
(FORM_FIELD_FILE_NAME, open('path_to_file/nasa2.jpg', 'rb')),
(FORM_FIELD_FILE_NAME, open('path_to_file/nasa3.tif', 'rb')),
]
[ ( FORM_FIELD_FILE_NAME open ( ' path_to_file / pyfile - 1 . pdf ' ' rb ' )) ( FORM_FIELD_FILE_NAME open ( ' path_to_file / test ' ' rb ' )) ( FORM_FIELD_FILE_NAME open ( ' path_to_file / 10mb . jpg ' ' rb ' )) ( FORM_FIELD_FILE_NAME open ( ' path_to_file / nasa2 . jpg ' ' rb ' )) ( FORM_FIELD_FILE_NAME open ( ' path_to_file / nasa3 . tif ' ' rb ' )) ]
self
file
> Path to the file that will be uploaded.
> Path to the file that will be uploaded .