(**kwargs)
return MultipartEncoder(fields=fields_dict)
initialize MultipartEncoder with uploading fields.

    Returns:
        MultipartEncoder: initialized MultipartEncoder object
initialize MultipartEncoder with uploading fields.
initialize MultipartEncoder with uploading fields .
def multipart_encoder(**kwargs):
    """ initialize MultipartEncoder with uploading fields.

    Returns:
        MultipartEncoder: initialized MultipartEncoder object

    """

    def get_filetype(file_path):
        file_type = filetype.guess(file_path)
        if file_type:
            return file_type.mime
        else:
            return "text/html"

    ensure_upload_ready()
    fields_dict = {}
    for key, value in kwargs.items():

        if os.path.isabs(value):
            # value is absolute file path
            _file_path = value
            is_exists_file = os.path.isfile(value)
        else:
            # value is not absolute file path, check if it is relative file path
            from httprunner.loader import load_project_meta

            project_meta = load_project_meta("")

            _file_path = os.path.join(project_meta.RootDir, value)
            is_exists_file = os.path.isfile(_file_path)

        if is_exists_file:
            # value is file path to upload
            filename = os.path.basename(_file_path)
            mime_type = get_filetype(_file_path)
            # TODO: fix ResourceWarning for unclosed file
            file_handler = open(_file_path, "rb")
            fields_dict[key] = (filename, file_handler, mime_type)
        else:
            fields_dict[key] = value

    return MultipartEncoder(fields=fields_dict)
def multipart_encoder ( * * kwargs ) : def get_filetype ( file_path ) : file_type = filetype . guess ( file_path ) if file_type : return file_type . mime else : return "text/html" ensure_upload_ready ( ) fields_dict = { } for key , value in kwargs . items ( ) : if os . path . isabs ( value ) : # value is absolute file path _file_path = value is_exists_file = os . path . isfile ( value ) else : # value is not absolute file path, check if it is relative file path from httprunner . loader import load_project_meta project_meta = load_project_meta ( "" ) _file_path = os . path . join ( project_meta . RootDir , value ) is_exists_file = os . path . isfile ( _file_path ) if is_exists_file : # value is file path to upload filename = os . path . basename ( _file_path ) mime_type = get_filetype ( _file_path ) # TODO: fix ResourceWarning for unclosed file file_handler = open ( _file_path , "rb" ) fields_dict [ key ] = ( filename , file_handler , mime_type ) else : fields_dict [ key ] = value return MultipartEncoder ( fields = fields_dict )