Hi.
I’m currently developing a file upload page and I want to receive the FormData (file to be uploaded) delivered from the front to the back end and upload it directly to the ‘sg_multi_files’ field of Shotgrid’s ‘Task’ entity with the REST API.
I managed to get the Upload URL by receiving the Shotgrid API token through the Shotgrid REST API guide.
The ‘storage_service’ I received is of the ‘s3’ type, but I don’t know how to upload it.
for file in uploaded_files:
if file.filename != '':
data = file.read()
####### Get Upload URL
headers = {
'Accept': 'application/json',
'Authorization': f'Bearer {access_token}'
}
get_upload = requests.get(f'{rest_url}/entity/Task/{sel_task_id}/{field_name}/_upload', params={'filename':{file.filename}},
headers=headers)
response = get_upload.json()
upload_url = response['links']['upload']
complete_url = response['links']['complete_upload']
####### Put Upload
headers = {
'Content-Type': file.content_type,
# 'Content-Type': 'image/*',
'x-amz-meta-original-filename': file.filename,
# 'x-amz-acl': 'public-read'
}
upload_file = requests.put(upload_url, data=data, headers=headers)
####### Post Upload
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Bearer {access_token}'
}
data = {
'upload_info': response['data'],
'links': response['links'],
'upload_data': {
'display_name': file.filename
}
}
complete_upload = requests.post(site_url+complete_url,headers=headers,data=data)
The above source is something I searched on the Internet and implemented
I am receiving 403 response from upload_file which is a put request
The post request, complete_upload, is responding to 500.
I’m so desperate for help right now