Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to upload a file to the agora server #62

Open
Toriong opened this issue Mar 17, 2023 · 2 comments
Open

Unable to upload a file to the agora server #62

Toriong opened this issue Mar 17, 2023 · 2 comments

Comments

@Toriong
Copy link

Toriong commented Mar 17, 2023

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.

@ycj3
Copy link

ycj3 commented Mar 21, 2023

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.

@Toriong
Copy link
Author

Toriong commented Mar 30, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants