Example #1
0
 def upload(self, filename='upload', **kwargs):
     if 'Content-MD5' not in request.headers:
         abort(400, 'Request must contain a valid "Content-MD5" header.')
     stage_path = config.get('upload_path')
     with nimsutil.TempDir(prefix='.tmp', dir=stage_path) as tempdir_path:
         hash_ = hashlib.sha1()
         upload_filepath = os.path.join(tempdir_path, filename)
         with open(upload_filepath, 'wb') as upload_file:
             for chunk in iter(lambda: request.body_file.read(2**20), ''):
                 hash_.update(chunk)
                 upload_file.write(chunk)
         if hash_.hexdigest() != request.headers['Content-MD5']:
             abort(400, 'Content-MD5 mismatch (or unset).')
         print 'upload from %s: %s [%s]' % (
             request.user_agent, os.path.basename(upload_filepath),
             nimsutil.hrsize(request.content_length))
         os.rename(
             upload_filepath,
             os.path.join(stage_path,
                          str(uuid.uuid1()) + '_' +
                          filename))  # add UUID to prevent clobbering files
Example #2
0
File: root.py Project: cni/nims
 def upload(self, filename='upload', **kwargs):
     if 'Content-MD5' not in request.headers:
         abort(400, 'Request must contain a valid "Content-MD5" header.')
     stage_path = config.get('upload_path')
     with nimsutil.TempDir(prefix='.tmp', dir=stage_path) as tempdir_path:
         hash_ = hashlib.sha1()
         upload_filepath = os.path.join(tempdir_path, filename)
         with open(upload_filepath, 'wb') as upload_file:
             for chunk in iter(lambda: request.body_file.read(2**20), ''):
                 hash_.update(chunk)
                 upload_file.write(chunk)
         if hash_.hexdigest() != request.headers['Content-MD5']:
             abort(400, 'Content-MD5 mismatch (or unset).')
         print 'upload from %s: %s [%s]' % (request.user_agent, os.path.basename(upload_filepath), nimsutil.hrsize(request.content_length))
         os.rename(upload_filepath, os.path.join(stage_path, str(uuid.uuid1()) + '_' + filename)) # add UUID to prevent clobbering files
Example #3
0
 def __str__(self):
     info = ' (%s) %s_%s_%s' % (self.pat_id, self.pfile.exam_no, self.pfile.series_no, self.pfile.acq_no) if self.pat_id else ''
     return '%s [%s]%s' % (self.basename, nimsutil.hrsize(self.size), info)
Example #4
0
 def __str__(self):
     info = ' (%s) %s_%s_%s' % (self.pat_id, self.pfile.exam_no,
                                self.pfile.series_no,
                                self.pfile.acq_no) if self.pat_id else ''
     return '%s [%s]%s' % (self.basename, nimsutil.hrsize(self.size), info)