Vivek
1
Hi everyone
I’m trying to upload a file using ayon_api.upload_file()
import ayon_api
endpoint_url = f"projects/{project_name}/files"
file_path = "/home/user/Desktop/scene.ma"
ayon_api.upload_file(endpoint_url, file_path)
when I’m running this getting below error:
405 Client Error: Method Not Allowed for url: {base_url}/api/projects/ptest/files
Hello,
Does it work when using rest API? Upload Project File
The endpoint is expecing POST method instead of default PUT.
import ayon_api
endpoint_url = f"projects/{project_name}/files"
file_path = "/home/user/Desktop/scene.ma"
ayon_api.upload_file(
endpoint_url,
file_path,
request_type=RequestTypes.post,
)
2 Likes
Vivek
5
Hi Illicit
thank you for the reply I tried to add the request_type but still getting the same error
This works on my side.
import ayon_api
from ayon_api.server_api import RequestTypes
from ayon_core.lib import get_media_mime_type
project_name = "AY_CG_demo"
endpoint_url = f"projects/{project_name}/files"
filename = "some_random_file.png"
file_path = rf"E:\Ynput\tmp\{filename}"
ayon_con = ayon_api.get_server_api_connection()
content_type = get_media_mime_type(file_path)
headers = ayon_con.get_headers(content_type)
headers["x-file-name"] = filename
output = ayon_con.upload_file(
endpoint_url,
file_path,
headers=headers,
request_type=RequestTypes.post,
)
print(output)
It gave me
>>> <Response [201]>
1 Like
This is the real fix here.
It came up here last week: Project files: Add upload helpers by iLLiCiTiT · Pull Request #306 · ynput/ayon-python-api · GitHub
Still pending review before a PR implements it directly in the exposed API methods there. For now make sure to specify the headers yourself.
1 Like