[API] Upload files in Python
Hello everyone.
I'm Japanese.
Honestly, I'm really a poor speaker of English. So please be kind and patient with me.
I try to upload the file while referring to the following URL.
I can upload files related to the application in this code.(My API)
# -*- coding: utf-8 -*-
from boxsdk import JWTAuth
from boxsdk import Client
# Configure JWT auth object
sdk = JWTAuth.from_settings_file('C:/Users/user/Desktop/box_conf/203407836_9cpi2izz_config.json')
# Get auth client
client = Client(sdk)
# Set upload values
file_path = 'C:/Users/user/Desktop/006.png'
file_name = 'photo.png'
folder_id = '0'
box_file = client.folder(folder_id).upload(file_path, file_name)
print(vars(box_file))
but I can't upload box user's folder in this code.
# -*- coding: utf-8 -*-
from boxsdk import JWTAuth
from boxsdk import Client
# Configure JWT auth object
sdk = JWTAuth.from_settings_file('C:/Users/user/Desktop/box_conf/203407836_9cpi2izz_config.json')
# Get auth client
client = Client(sdk)
# Set upload values
file_path = 'C:/Users/user/Desktop/006.png'
file_name = 'photo.png'
folder_id = '0'
user_id = '*******'
box_file = client.as_user(user_id).folder(folder_id).upload(file_path, file_name)
An error has occurred.
##############################################################
Traceback (most recent call last):
File "test_boxsdk3.py", line 29, in
box_file = client.as_user(userid).folder(folder_id).upload(file_path, file_name)
File "C:\Users\user\script\study04\boxsdk\object\cloneable.py", line 21, in as_user
return self.clone(self.session.as_user(user))
File "C:\Users\user\script\study04\boxsdk\session\session.py", line 243, in as_user
kwargs['default_headers']['As-User'] = user.object_id
AttributeError: 'str' object has no attribute 'object_id'
##############################################################
I'd like some advice.
Thanks.
Please sign in to leave a comment.
Comments
5 comments