Unable to upload a file to the agora server
I am uploading a file to the Agora server to reference it via its' URL when a user sends a message to their peer.
Here's how I structure the request that is sent to Agora's server:
pathToFile = 'C:\Users\gtori\OneDrive\Desktop\messaging_hud\users\files\testFile.png'
headers = {'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW', 'Authorization': 'Bearer token'}
agoraUrl = https://a41.chat.agora.io/orgName/appName/chatfiles
res = requests.post(agoraUrl, { file: pathToFile }, headers=headers)
The response that I am getting from agora is a 400 error:
{'error': 'illegal_argument', 'exception': 'java.lang.IllegalArgumentException', 'timestamp': 1679065052094, 'duration': 1, 'error_description': 'file must be provided.'} fromServer: {'msg': 'The file was not uploaded successfully to agora server.'}
Even though the path to the file is valid, I get a True boolean when I test its validity of it by passing it in for os.path.exists().
I'm following Agora's documentation linked here under "Upload a file": https://docs.agora.io/en/agora-chat/restful-api/message-management?platform=unity#upload-a-file
Thanks for any input.
Request example in Python LANGUAGE
import requests
headers = {
'Authorization': 'Bearer {YourToken}',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW',
'restrict-access': 'true',
}
files = {
'file': open('/Users/test/9.2/chat/image/IMG_2953.JPG', 'rb'),
}
response = requests.post('https://XXXX/XXXX/XXXX/chatfiles', headers=headers, files=files)
Hope this helps.
Thanks for the reply. But that's not working. According to the official docs, what should be passed for the post-request body is the path to the file. However, that's not working as well, even though I verified that the path is valid.