コード例 #1
0
ファイル: files.py プロジェクト: ctcble/canopsis
def delete_file(metaId=None):
	account = get_account()
	storage = get_storage(account=account, namespace=namespace)
	
	rfiles = []
	data = request.body.readline()
	items = []
	try:
		items = json.loads(data)
	except:
		logger.warning('Invalid data in request payload')	
		
	## Only accept list for multiremove
	if not isinstance(items, list):
		items = []
	
	if metaId and not items:
		rfile = get_cfile(metaId, storage)
		rfiles.append(rfile)
	else:
		logger.debug('Multi-remove: %s' % data)
			
		for item in items:
			rfile = get_cfile(item['id'], storage)
			rfiles.append(rfile)
						
	logger.debug('Remove %s files' % len(rfiles))
	try:
		for rfile in rfiles:
			rfile.remove()
		return {'total': len(rfiles),"data": [] ,"success":True}
	except:
		logger.error('Failed to remove file')
		return HTTPError(500, "Failed to remove file")
コード例 #2
0
ファイル: files.py プロジェクト: jbbqqf/canopsis
def delete_file(metaId=None):
	account = get_account()
	storage = get_storage(account=account, namespace=namespace)
	
	rfiles = []
	data = request.body.readline()
	items = []
	try:
		items = json.loads(data)
	except:
		logger.warning('Invalid data in request payload')	
		
	## Only accept list for multiremove
	if not isinstance(items, list):
		items = []
	
	if metaId and not items:
		rfile = get_cfile(metaId, storage)
		rfiles.append(rfile)
	else:
		logger.debug('Multi-remove: %s' % data)
			
		for item in items:
			rfile = get_cfile(item['id'], storage)
			rfiles.append(rfile)
						
	logger.debug('Remove %s files' % len(rfiles))
	try:
		for rfile in rfiles:
			rfile.remove()
		return {'total': len(rfiles),"data": [] ,"success":True}
	except:
		logger.error('Failed to remove file')
		return HTTPError(500, "Failed to remove file")
コード例 #3
0
ファイル: cfile-Myunittest.py プロジェクト: EzanLTD/canopsis
	def test_10_CheckFileRemove(self):
		with self.assertRaises(NoFile):
			binary = storage.get_binary(bin_id)
			
		with self.assertRaises(KeyError):
			get_cfile(meta_id, storage)
		
		if myfile.check():
			raise Exception('cfile is not deleted ...')
コード例 #4
0
    def test_10_CheckFileRemove(self):
        with self.assertRaises(NoFile):
            binary = storage.get_binary(bin_id)

        with self.assertRaises(KeyError):
            get_cfile(meta_id, storage)

        if myfile.check():
            raise Exception('cfile is not deleted ...')
コード例 #5
0
ファイル: files.py プロジェクト: dmichau/canopsis
def files(metaId=None):
	
	if metaId:
		account = get_account()
		storage = get_storage(account=account, namespace=namespace)
	
		logger.debug("Get file '%s'" % metaId)
		
		rfile = get_cfile(metaId, storage)
		
		file_name = rfile.data['file_name']
		content_type = rfile.data['content_type']
		
		logger.debug(" + File name:    %s" % file_name)
		logger.debug(" + Content type: %s" % content_type)
		logger.debug(" + Bin Id:       %s" % rfile.get_binary_id())
		
		data = rfile.get()

		if data:
			response.headers['Content-Disposition'] = 'attachment; filename="%s"' % file_name
			response.headers['Content-Type'] = content_type
			try:
				return data
			except Exception, err:
				logger.error(err)
		else:
			logger.error('No report found in gridfs')
			return HTTPError(404, " Not Found")
コード例 #6
0
def files(metaId=None):

    # Arg option for attachement http option (default: True)
    as_attachment = True
    if request.params.get('as_attachment') in ['false', 'False', '0']:
        as_attachment = False

    if metaId:
        account = get_account()
        storage = get_storage(account=account, namespace=namespace)

        logger.debug("Get file '%s'" % metaId)

        try:
            rfile = get_cfile(metaId, storage)
        except Exception as err:
            logger.error('File not found: %s' % err)
            return HTTPError(404, "File not found")

        file_name = rfile.data['file_name']
        content_type = rfile.data['content_type'] or 'application/octet-stream'

        logger.debug(" + File name:    %s" % file_name)
        logger.debug(" + Content type: %s" % content_type)
        logger.debug(" + Bin Id:       %s" % rfile.get_binary_id())

        try:
            data = rfile.get()
        except Exception as err:
            logger.error('Error while file fetching: %s' % err)

        if data:
            if as_attachment:
                try:
                    response.headers[
                        'Content-Disposition'] = 'attachment; filename="%s"' % file_name.encode(
                            "utf8")
                except Exception as err:
                    logger.error(err)
                    return HTTPError(500, "Impossible to encode file_name.")

            response.headers['Content-Type'] = content_type
            try:
                return data
            except Exception as err:
                logger.error(err)
        else:
            logger.error('File not found in gridfs')
            return HTTPError(404, "File not found")
    else:
        return list_files()
コード例 #7
0
ファイル: files.py プロジェクト: ctcble/canopsis
def files(metaId=None):
	
	# Arg option for attachement http option (default: True)
	as_attachment = True
	if request.params.get('as_attachment') in ['false', 'False', '0']:
		as_attachment = False

	if metaId:
		account = get_account()
		storage = get_storage(account=account, namespace=namespace)
	
		logger.debug("Get file '%s'" % metaId)
		
		try:
			rfile = get_cfile(metaId, storage)
		except Exception as err:
			logger.error('File not found: %s' % err)
			return HTTPError(404, "File not found")
		
		file_name = rfile.data['file_name']
		content_type = rfile.data['content_type'] or 'application/octet-stream'
		
		logger.debug(" + File name:    %s" % file_name)
		logger.debug(" + Content type: %s" % content_type)
		logger.debug(" + Bin Id:       %s" % rfile.get_binary_id())
		
		try:
			data = rfile.get()
		except Exception as err:
			logger.error('Error while file fetching: %s' % err)

		if data:
			if as_attachment:
				try:
					response.headers['Content-Disposition'] = 'attachment; filename="%s"' % file_name.encode("utf8")
				except Exception as err:
					logger.error(err)
					return HTTPError(500, "Impossible to encode file_name.")

			response.headers['Content-Type'] = content_type
			try:
				return data
			except Exception as err:
				logger.error(err)
		else:
			logger.error('File not found in gridfs')
			return HTTPError(404, "File not found")
	else:
		return list_files()
コード例 #8
0
ファイル: files.py プロジェクト: hesaul/canopsis
def files(metaId=None):

    if metaId:
        account = get_account()
        storage = get_storage(account=account, namespace=namespace)

        logger.debug("Get file '%s'" % metaId)

        try:
            rfile = get_cfile(metaId, storage)
        except Exception as err:
            logger.error('File not found: %s' % err)
            return HTTPError(404, "File not found")

        file_name = rfile.data['file_name']
        content_type = rfile.data['content_type']

        logger.debug(" + File name:    %s" % file_name)
        logger.debug(" + Content type: %s" % content_type)
        logger.debug(" + Bin Id:       %s" % rfile.get_binary_id())

        try:
            data = rfile.get()
        except Exception as err:
            logger.error('Error while file fetching: %s' % err)

        if data:
            try:
                response.headers[
                    'Content-Disposition'] = 'attachment; filename="%s"' % file_name.encode(
                        "utf8")
            except Exception as err:
                logger.error(err)
                return HTTPError(500, "Impossible to encode file_name.")

            response.headers['Content-Type'] = content_type
            try:
                return data
            except Exception as err:
                logger.error(err)
        else:
            logger.error('File not found in gridfs')
            return HTTPError(404, "File not found")
    else:
        return list_files()
コード例 #9
0
ファイル: files.py プロジェクト: Httqm/canopsis
def files(metaId=None):
	
	if metaId:
		account = get_account()
		storage = get_storage(account=account, namespace=namespace)
	
		logger.debug("Get file '%s'" % metaId)
		
		try:
			rfile = get_cfile(metaId, storage)
		except Exception as err:
			logger.error('File not found: %s' % err)
			return HTTPError(404, "File not found")
		
		file_name = rfile.data['file_name']
		content_type = rfile.data['content_type']
		
		logger.debug(" + File name:    %s" % file_name)
		logger.debug(" + Content type: %s" % content_type)
		logger.debug(" + Bin Id:       %s" % rfile.get_binary_id())
		
		try:
			data = rfile.get()
		except Exception as err:
			logger.error('Error while file fetching: %s' % err)

		if data:
			try:
				response.headers['Content-Disposition'] = 'attachment; filename="%s"' % file_name.encode("utf8")
			except Exception as err:
				logger.error(err)
				return HTTPError(500, "Impossible to encode file_name.")

			response.headers['Content-Type'] = content_type
			try:
				return data
			except Exception as err:
				logger.error(err)
		else:
			logger.error('File not found in gridfs')
			return HTTPError(404, "File not found")
	else:
		return list_files()