mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Send content type to API when uploading print job
This commit is contained in:
parent
2b8c9c17bb
commit
5db6bd9a9b
2 changed files with 8 additions and 2 deletions
|
@ -129,7 +129,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
|
|
||||||
stream = io.StringIO() if file_format["mode"] == FileWriter.OutputMode.TextMode else io.BytesIO()
|
stream = io.StringIO() if file_format["mode"] == FileWriter.OutputMode.TextMode else io.BytesIO()
|
||||||
writer.write(stream, nodes)
|
writer.write(stream, nodes)
|
||||||
self._sendPrintJob(file_name + "." + file_format["extension"], stream)
|
self._sendPrintJob(file_name + "." + file_format["extension"], file_format["mime_type"], stream)
|
||||||
|
|
||||||
# TODO: This is yanked right out of ClusterUM3OutputDevice, great candidate for a utility or base class
|
# TODO: This is yanked right out of ClusterUM3OutputDevice, great candidate for a utility or base class
|
||||||
def _determineFileFormat(self, file_handler) -> Optional[Dict[str, Union[str, int]]]:
|
def _determineFileFormat(self, file_handler) -> Optional[Dict[str, Union[str, int]]]:
|
||||||
|
@ -339,12 +339,13 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
model.updateOwner(job.owner)
|
model.updateOwner(job.owner)
|
||||||
model.updateState(job.status)
|
model.updateState(job.status)
|
||||||
|
|
||||||
def _sendPrintJob(self, file_name: str, stream: Union[io.StringIO, io.BytesIO]) -> None:
|
def _sendPrintJob(self, file_name: str, content_type: str, stream: Union[io.StringIO, io.BytesIO]) -> None:
|
||||||
mesh = stream.getvalue()
|
mesh = stream.getvalue()
|
||||||
|
|
||||||
request = JobUploadRequest()
|
request = JobUploadRequest()
|
||||||
request.job_name = file_name
|
request.job_name = file_name
|
||||||
request.file_size = len(mesh)
|
request.file_size = len(mesh)
|
||||||
|
request.content_type = content_type
|
||||||
|
|
||||||
Logger.log("i", "Creating new cloud print job: %s", request.__dict__)
|
Logger.log("i", "Creating new cloud print job: %s", request.__dict__)
|
||||||
self.put("{}/jobs/upload".format(self.CURA_API_ROOT), data = json.dumps({"data": request.__dict__}),
|
self.put("{}/jobs/upload".format(self.CURA_API_ROOT), data = json.dumps({"data": request.__dict__}),
|
||||||
|
@ -355,6 +356,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
if status_code > 204 or not isinstance(response, dict) or "data" not in response:
|
if status_code > 204 or not isinstance(response, dict) or "data" not in response:
|
||||||
Logger.log("w", "Got unexpected response while trying to add print job to cluster: {}, {}"
|
Logger.log("w", "Got unexpected response while trying to add print job to cluster: {}, {}"
|
||||||
.format(status_code, response))
|
.format(status_code, response))
|
||||||
|
self.writeError.emit()
|
||||||
return
|
return
|
||||||
|
|
||||||
# TODO: Multipart upload
|
# TODO: Multipart upload
|
||||||
|
@ -368,6 +370,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
if status_code > 204:
|
if status_code > 204:
|
||||||
Logger.logException("w", "Received unexpected response from the job upload: %s, %s.", status_code,
|
Logger.logException("w", "Received unexpected response from the job upload: %s, %s.", status_code,
|
||||||
bytes(reply.readAll()).decode())
|
bytes(reply.readAll()).decode())
|
||||||
|
self.writeError.emit()
|
||||||
return
|
return
|
||||||
|
|
||||||
Logger.log("i", "Print job uploaded successfully: %s", reply.readAll())
|
Logger.log("i", "Print job uploaded successfully: %s", reply.readAll())
|
||||||
|
@ -379,7 +382,9 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
if status_code > 204 or not isinstance(response, dict) or "data" not in response:
|
if status_code > 204 or not isinstance(response, dict) or "data" not in response:
|
||||||
Logger.log("w", "Got unexpected response while trying to request printing: %s, %s",
|
Logger.log("w", "Got unexpected response while trying to request printing: %s, %s",
|
||||||
status_code, response)
|
status_code, response)
|
||||||
|
self.writeError.emit()
|
||||||
return
|
return
|
||||||
|
|
||||||
print_response = PrintResponse(**response["data"])
|
print_response = PrintResponse(**response["data"])
|
||||||
Logger.log("i", "Print job requested successfully: %s", print_response.__dict__)
|
Logger.log("i", "Print job requested successfully: %s", print_response.__dict__)
|
||||||
|
self.writeFinished.emit()
|
||||||
|
|
|
@ -108,6 +108,7 @@ class JobUploadRequest(BaseModel):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.file_size = None # type: int
|
self.file_size = None # type: int
|
||||||
self.job_name = None # type: str
|
self.job_name = None # type: str
|
||||||
|
self.content_type = None # type: str
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue