upload.py 863 B

1234567891011121314151617181920212223242526272829
  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. @tornado.web.authenticated
  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', '')})