コード例 #1
0
ファイル: upload.py プロジェクト: meliu/thunder
 def upload(self, **kwargs):
     try:
         import sae.storage
         s = sae.storage.Client()
         obj = sae.storage.Ojbect(self.files[0]['body'])
         obj_name = int(time.time()) + random_str(8) + \
                 self.files[0]['format'].lower()
         s.put(self.domain, obj_name, obj)
         obj_url = s.url(self.domain, obj_name)
         return (obj_name, obj_url)
     except ImportError:
         obj = self.files[0]['body']
         obj_name = int(time.time()) + random_str(8) + \
                 self.files[0]['format'].lower()
         obj_url = '/static/upload/' + obj_name
         with open(obj_url, 'wb') as f:
             f.write(obj)
         return (obj_name, obj_url)
     except:
         return None
コード例 #2
0
ファイル: upload.py プロジェクト: meliu/thunder
 def upload_all(self, **kwargs):
     try:
         import sae.storage
         s = sae.storage.Client()
         for file in self.files:
             obj = sae.storage.Object(file['body'])
             obj_name = int(time.time()) + random_str(8) + \
                     file['format'].lower()
             s.put(self.domain, obj_name, obj)
             obj_url = s.url(self.domain, obj_name)
         return True
     except ImportError:
         for file in self.files:
             obj = file['body']
             obj_name = int(time.time()) + random_str(8) + \
                     file['format'].lower()
             obj_url = '/static/upload/' + obj_name
             with open(obj_url, 'wb') as f:
                 f.write(obj)
         return True
     except:
         return False