upload.py 838 B

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. """
  3. demeter web page
  4. name:upload.py
  5. author:rabin
  6. """
  7. from .__load__ import *
  8. from datetime import *
  9. import os
  10. import uuid
  11. class upload_path(Load):
  12. @Web.auth
  13. @Web.setting
  14. def post(self, *args, **kwargs):
  15. url = self.request.protocol + "://" + self.request.host
  16. file_metas = self.request.files["file"]
  17. # print(file_metas)
  18. day = str(date.today())
  19. day = day.split('-')
  20. for meta in file_metas:
  21. #meta['filename']
  22. file_name = str(uuid.uuid5(uuid.uuid1(), 'file'))
  23. file_path = day[0] + '/' + day[1] + '/' + day[2]
  24. file_path = File.mkdirs(os.path.join(Demeter.path, 'runtime','upload', file_path)) + '/' + Demeter.md5(file_name) + '.jpg'
  25. with open(file_path, 'wb') as up:
  26. up.write(meta['body'])
  27. self.out('yes', {'src':url + file_path.replace(Demeter.path + 'runtime', '')})