upload_assets.py 1013 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import requests
  2. import json
  3. api_url = "https://canvas-api-test.anvil.app/_/api"
  4. def upload_assets(json_file_path, api_url):
  5. # Open and read the JSON file
  6. with open(json_file_path, "r") as file:
  7. assets_data = json.load(file)
  8. payload = {"assets": assets_data}
  9. print(payload)
  10. # Make the POST request to the API endpoint
  11. url = f"{api_url}/management/uploadAssets"
  12. response = requests.post(url, json=payload)
  13. # Check the response
  14. if response.status_code == 200:
  15. print("Assets uploaded successfully")
  16. else:
  17. print(f"Failed to upload assets: {response.status_code}")
  18. print(response.json())
  19. if __name__ == "__main__":
  20. # Path to the JSON file containing the assets
  21. json_file_path = "D:/Git/ap-canvas-creation-module/01_backend/database/assets.json"
  22. # Application ID and sign (replace with actual values)
  23. app_id = "your_app_id"
  24. sign = "your_sign"
  25. # Call the upload function
  26. upload_assets(json_file_path, api_url)