Upload file using python requests

后端 未结 3 1645
失恋的感觉
失恋的感觉 2021-02-09 20:44

I\'ve been trying to upload a file using the box v2 api with requests.

So far I had little luck though. Maybe someone here can help me see what I\'m actually doing wrong

3条回答
  •  渐次进展
    2021-02-09 21:20

    My solution, using requests:

    def upload_to_box(folder_id, auth_token, file_out):
        headers = { 'Authorization' : BOX_AUTH.format(auth_token) }
        url = 'https://api.box.com/2.0/files/content'
        files = { 'filename': (new_file_name, open(file_out,'rb')) }
        data = { 'folder_id': folder_id }
        response = requests.post(url, params=data, files=files, headers=headers)
    

    It would be nice if you could specify the new_copy parameter but there's nothing documented for it and it doesn't seem to work.

提交回复
热议问题