A python library for interacting with Teknik Services
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

uploads.py 937B

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