Exemplo n.º 1
0
    def get_file_upload(self):
        try:
            if len(self.request.files) != 1:
                raise errors.InvalidInputFormat("cannot accept more than a file upload at once")

            chunk_size = len(self.request.files['file'][0]['body'])
            total_file_size = int(self.request.arguments['flowTotalSize'][0]) if 'flowTotalSize' in self.request.arguments else chunk_size
            flow_identifier = self.request.arguments['flowIdentifier'][0] if 'flowIdentifier' in self.request.arguments else generateRandomKey(10)

            if ((chunk_size / (1024 * 1024)) > GLSettings.memory_copy.maximum_filesize or
                (total_file_size / (1024 * 1024)) > GLSettings.memory_copy.maximum_filesize):
                log.err("File upload request rejected: file too big")
                raise errors.FileTooBig(GLSettings.memory_copy.maximum_filesize)

            if flow_identifier not in GLUploads:
                f = GLSecureTemporaryFile(GLSettings.tmp_upload_path)
                GLUploads[flow_identifier] = f
            else:
                f = GLUploads[flow_identifier]

            f.write(self.request.files['file'][0]['body'])

            if 'flowChunkNumber' in self.request.arguments and 'flowTotalChunks' in self.request.arguments:
                if self.request.arguments['flowChunkNumber'][0] != self.request.arguments['flowTotalChunks'][0]:
                    return None

            uploaded_file = {}
            uploaded_file['filename'] = self.request.files['file'][0]['filename']
            uploaded_file['content_type'] = self.request.files['file'][0]['content_type']
            uploaded_file['body_len'] = total_file_size
            uploaded_file['body_filepath'] = f.filepath
            uploaded_file['body'] = f

            upload_time = time.time() - f.creation_date

            # file uploads works on chunk basis so that we count 1 the file upload
            # as a whole in function get_file_upload()
            for event in outcoming_event_monitored:
                if event['status_checker'](self._status_code) and \
                        event['method'] == self.request.method and \
                        event['handler_check'](self.request.uri):
                    EventTrack(event, upload_time)

            return uploaded_file

        except errors.FileTooBig:
            raise  # propagate the exception

        except Exception as exc:
            log.err("Error while handling file upload %s" % exc)
            return None
Exemplo n.º 2
0
    def on_finish(self):
        """
        Here is implemented:
          - The performance analysts
          - the Request/Response logging
        """
        for event in outcoming_event_monitored:
            if event['status_checker'](self._status_code) and \
                   event['method'] == self.request.method and \
                   event['handler_check'](self.request.uri):
                EventTrack(event, self.request.request_time())

        self.handler_time_analysis_end()
        self.handler_request_logging_end()
Exemplo n.º 3
0
    def get_file_upload(self):
        try:
            if (int(self.request.arguments['flowTotalSize'][0]) /
                (1024 * 1024)) > GLSettings.memory_copy.maximum_filesize:
                log.err("File upload request rejected: file too big")
                raise errors.FileTooBig(
                    GLSettings.memory_copy.maximum_filesize)

            if self.request.arguments['flowIdentifier'][0] not in GLUploads:
                f = GLSecureTemporaryFile(GLSettings.tmp_upload_path)
                GLUploads[self.request.arguments['flowIdentifier'][0]] = f
            else:
                f = GLUploads[self.request.arguments['flowIdentifier'][0]]

            f.write(self.request.files['file'][0]['body'])

            if self.request.arguments['flowChunkNumber'][
                    0] != self.request.arguments['flowTotalChunks'][0]:
                return None

            uploaded_file = {}
            uploaded_file['filename'] = self.request.files['file'][0][
                'filename']
            uploaded_file['content_type'] = self.request.files['file'][0][
                'content_type']
            uploaded_file['body_len'] = int(
                self.request.arguments['flowTotalSize'][0])
            uploaded_file['body_filepath'] = f.filepath
            uploaded_file['body'] = f

            upload_time = time.time() - f.creation_date

            # file uploads works on chunk basis so that we count 1 the file upload
            # as a whole in function get_file_upload()
            for event in outcoming_event_monitored:
                if event['status_checker'](self._status_code) and \
                        event['method'] == self.request.method and \
                        event['handler_check'](self.request.uri):
                    EventTrack(event, upload_time)

            return uploaded_file

        except errors.FileTooBig:
            raise  # propagate the exception

        except Exception as exc:
            log.err("Error while handling file upload %s" % exc)
            return None
Exemplo n.º 4
0
    def on_finish(self):
        """
        Here is implemented:
          - The performance analysts
          - the Request/Response logging
        """
        # file uploads works on chunk basis so that we count 1 the file upload
        # as a whole in function get_file_upload()
        if not self.filehandler:
            for event in outcoming_event_monitored:
                if event['status_checker'](self._status_code) and \
                        event['method'] == self.request.method and \
                        event['handler_check'](self.request.uri):
                    EventTrack(event, self.request.request_time())

        self.handler_time_analysis_end()
        self.handler_request_logging_end()