Last active
October 10, 2019 09:32
-
-
Save nulpunkt/ab1e139315867668d6e1256083307ecf to your computer and use it in GitHub Desktop.
Upload a file to Skyfish via the API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import sys | |
import time | |
import os | |
if len(sys.argv) < 3: | |
raise Exception("Usage: python throw-into-skyfish.py <folder_id> <file_path>") | |
auth = {'Authorization': 'CBX-SIMPLE-TOKEN Token=TOKENGOESHERE'} | |
register = requests.post('https://api.colourbox.com/upload/register', data=json.dumps({'folder': int(sys.argv[1])}), headers=auth).json() | |
fields = {} | |
for field in register['fields']: | |
if field['name'] != 'file': | |
fields[field['name']] = field['value'] | |
media_upload = requests.post(register['action'], files={'file': open(sys.argv[2], 'rb')}, data=fields).json() | |
media = requests.get('https://api.colourbox.com/media/' + str(media_upload['media_id']), headers=auth) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment