Пример #1
0
	def get(self):
		#self.write("Hello, world")
		print("lkj LkjDownFileHandler request.values:%s" % str(self.request) )
		
		filename = self.request.uri
		filename = filename.split("=", 2)
		#print("filename:%s" % str(filename))
		
		from octoprint.server import fileManager
		baseFolder = fileManager._storage("fbotSdcard").get_basefolder()
		#print("lkj downloadSDGcodeFiles 3.31 baseFolder:%s" % baseFolder )
			
		
		print("lkj downloadSDGcodeFiles 4, filename[1]=%s" % str(filename[1]))
		fileFullName = baseFolder + "/" + filename[1]		

		
		buf_size = 1024
		print("download file handler:%s" % fileFullName)
		self.set_header ('Content-Type', 'application/octet-stream')
		self.set_header ('Content-Disposition', 'attachment; filename='+ filename[1])
		with open(fileFullName, 'rb') as f:
			while True:
				data = f.read(buf_size)
				if not data:
					break
				self.write(data)
		self.finish()
Пример #2
0
def readGcodeFilesForOrigin(origin):
	if origin not in [FileDestinations.LOCAL, FileDestinations.SDCARD, FileDestinations.FastbotSDCARD]:
		return make_response("Unknown origin: %s" % origin, 404)

	files = _getFileList(origin)
	print("lkj readGcodeFilesForOrigin origin:%s" % origin )
	print("lkj readGcodeFilesForOrigin files:%s" % str(files) )
	if origin == FileDestinations.LOCAL:
		return jsonify(files=files, free=util.getFreeBytes(settings().getBaseFolder("uploads")))
	elif origin == FileDestinations.FastbotSDCARD:
		return jsonify(files=files, sdFree=util.getFreeBytes(fileManager._storage(origin).get_basefolder()))
	else:
		return jsonify(files=files)
Пример #3
0
def readGcodeFiles():
	filter = None
	if "filter" in request.values:
		filter = request.values["filter"]
	if filter is not None:
		print("lkj readGcodeFiles filter:%s" % repr(filter) )
	print("lkj readGcodeFiles request.values:%s" % str(request.values) )
	
	files = _getFileList(FileDestinations.LOCAL, filter=filter)
	print("lkj 1 readGcodeFiles files:%s" % str(files) )
	#lkj files.extend(_getFileList(FileDestinations.SDCARD))
	sdFree = 0
	if printer.isSdReady():
		files.extend(_getFileList(FileDestinations.FastbotSDCARD))
		sdFree = util.getFreeBytes(fileManager._storage(FileDestinations.FastbotSDCARD).get_basefolder())
		print("lkj 2 readGcodeFiles files:%s, sdFree:%s" % (str(files), str(sdFree)) )
		
	return jsonify(files=files, free=util.getFreeBytes(settings().getBaseFolder("uploads")), sdFree=sdFree)
Пример #4
0
def downloadSDGcodeFiles():
	data = request.json
	
	fileName = None
	if "filename" in data:
		print("lkj downloadSDGcodeFiles 3.4")
		fileName = data["filename"]
		
	if "origin" in data:
		print("lkj downloadSDGcodeFiles 3.4")
		origin = data["origin"]	
		
	print("lkj downloadSDGcodeFiles request.values:%s" % str(request.values) )
	print("lkj downloadSDGcodeFiles data:%s" % str(data) )
	
	if origin not in [FileDestinations.LOCAL, FileDestinations.SDCARD, FileDestinations.FastbotSDCARD]:
		return make_response("Unknown origin: %s" % origin, 404)
	print("lkj downloadSDGcodeFiles 1")
	#selectAfterUpload = "select" in request.values.keys() and request.values["select"] in valid_boolean_trues
	#printAfterSelect = "print" in request.values.keys() and request.values["print"] in valid_boolean_trues

	if origin == FileDestinations.FastbotSDCARD  and  not printer.isSdReady():
		return jsonify("")
	print("lkj downloadSDGcodeFiles 2")
	
		
	
	baseFolder = fileManager._storage(origin).get_basefolder()
	print("lkj downloadSDGcodeFiles 3.31 " )
		
	
	print("lkj downloadSDGcodeFiles 4")
	fileFullName = baseFolder + "/" + fileName
	print("lkj downloadSDGcodeFiles 5")
	buf_size = 4096
	print("download file handler:%s" % fileFullName)
	response = make_response(view_function())
	response.headers['Content-Type'] = 'application/octet-stream'
	response.headers['Content-Disposition'] = 'attachment; filename='+fileName
	response.write
	return response
	'''