Late reply, so I don't think it will be helpful anymore, but if you still need it or want to compare codes:
function variables: entryID is an overarching tracker. file_list is a list of files (fullpath) that i want to upload.
Hope this helps whoever comes across this!
function variables: entryID is an overarching tracker. file_list is a list of files (fullpath) that i want to upload.
Code:
def upload_file(entryID, file_list): #upload to UploadFileServlet url_post = 'https://mail.examplehost.com/service/upload?ftm=raw,extended' fn_no = 0 uploadID_list = [] for filename in file_list: fn_no += 1 fn = {'file': ( os.path.basename(filename).replace(f"{entryID}_","") , open(filename, 'rb'))} client_token = datetime.today().strftime('%Y%m%d%H%M%S') + '_' + entryID + '_' + str(fn_no) data = { 'requestId':client_token } print(f'Uploading %s to the UploadFileServlet...' % os.path.basename(filename) ) cookies = { 'ZM_AUTH_TOKEN': usr_token } r = requests.post(url_post,data=data,files=fn,cookies=cookies) if '200' in r.text: print('Upload successful.') else: print('Upload failed.') #extract server_token print('Extracting upload ID...') server_token_regex = re.compile(rf"'{client_token}','[^']*'") server_token_search = server_token_regex.search(r.text) server_token = re.sub(rf"'{client_token}',",'', server_token_search.group()).strip() server_token = re.sub("'",'',server_token) print('Upload ID extracted.') uploadID_list.append(server_token) return uploadID_list
Statistics: Posted by rikacain — Tue Feb 06, 2024 5:50 pm