A python library for interacting with Teknik Services
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uploads.py 819B

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (c) 2017 by Uncled1023 <admin@teknik.io>
  2. #
  3. # License BSD 3-Clause
  4. # Base Libraries
  5. import base64
  6. import json
  7. # Local Libraries
  8. from . import util
  9. # Dependencies
  10. import requests
  11. # Main Functions
  12. def UploadFile(url, filePath, username, authToken):
  13. files = {'file': open(filePath, "rb")}
  14. if url is None:
  15. url = util.defaultUrl
  16. if username is None:
  17. username = util.defaultUsername
  18. if authToken is None:
  19. authToken = util.defaultToken
  20. # Create a header if they have added auth info
  21. headers = {}
  22. if username != '' and authToken != '':
  23. encAuth = base64.b64encode(username + ':' + authToken)
  24. headers = {'Authorization': 'Basic ' + encAuth}
  25. r = requests.post(util.GetUrl(url, 'upload'), files=files, headers=headers)
  26. jObj = json.loads(r.text)
  27. return jObj