upload.py 860 B

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