Exemplo n.º 1
0
    def receiveFile(self):
        # 检查文件格式
        upload_file_name = str(self.request.FILES['file'])
        suffix = self.checkFileFormat(upload_file_name)
        if not self.result:
            return None

        # 创建存储目录
        storage_path = self.makeStoragePath()
        if not self.result:
            return None

        # make file storage full path
        if self.keep_origin_filename:
            file_path = os.path.join(storage_path, upload_file_name)
        else:
            uuid = genUUID(64)
            file_path = os.path.join(storage_path, f'{uuid}.{suffix}')
            while os.path.isfile(file_path):
                uuid = genUUID(64)
                file_path = os.path.join(storage_path, f'{uuid}.{suffix}')

        # Read file content and save it.
        form = UploadFileForm(self.request.POST, self.request.FILES)
        if form.is_valid():
            with open(file_path, 'wb+') as f:
                for chunk in self.request.FILES['file'].chunks():
                    f.write(chunk)
            self.result_data = {
                'result': 'SUCCESS',
                'message': 'To upload file succeeded.',
                'file_path': file_path
            }
        else:
            self.error('ERROR: Invalid file uploading post.', http_status=400)
 def delay(*args, **kwargs):
     client = AsyncTaskClient()
     err = 'UUID_EXIST'
     while err == 'UUID_EXIST':
         uuid = genUUID(64)
         if not tracking:
             err = None
             break
         _name = name if name else func.__name__
         err = client.record(uuid, name=_name)
         if err is not None and err != 'UUID_EXIST':
             return err
     return client.go(uuid, func.__name__, func.__module__, tracking, *args,
                      **kwargs)
Exemplo n.º 3
0
 def delay(*args, **kwargs):
     client = AsyncClient()
     err = 'UUID_EXIST'
     while err == 'UUID_EXIST':
         uuid = genUUID(64)
         if not tracking:
             err = None
             break
         _name = name if name else func.__name__
         err = client.record(uuid, name=_name)
         if err is not None and err != 'UUID_EXIST':
             return err
     main = partial(client.go, uuid, func.__name__, func.__module__,
                    tracking, *args, **kwargs)
     asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy(
     ))  # To make ioloop runnable in any thread within Django.
     try:
         ioloop.IOLoop.current().run_sync(main)
     except Exception as e:
         return str(e)
Exemplo n.º 4
0
 def addToken(self):
     if not self.checked_params.get('username'):
         self.checked_params['username'] = genUUID(8)
     self.checked_params['token'] = genUUID(64)
     self.addData(AuthToken)