Add file data to PUT request

The main point of the whole request, really.

Contributes to issue CURA-8609.
This commit is contained in:
Ghostkeeper 2021-10-12 12:56:19 +02:00
parent d5e3ed4c0e
commit f0d69cbef2
No known key found for this signature in database
GPG key ID: 68F39EA88EEED5FF

View file

@ -35,6 +35,7 @@ class UploadMaterialsJob(Job):
super().__init__()
self._material_sync = material_sync
self._scope = JsonDecoratorScope(UltimakerCloudScope(cura.CuraApplication.CuraApplication.getInstance())) # type: JsonDecoratorScope
self._archive_filename = None # type: Optional[str]
uploadCompleted = Signal()
uploadProgressChanged = Signal()
@ -42,8 +43,9 @@ class UploadMaterialsJob(Job):
def run(self):
archive_file = tempfile.NamedTemporaryFile("wb", delete = False)
archive_file.close()
self._archive_filename = archive_file.name
self._material_sync.exportAll(QUrl.fromLocalFile(archive_file.name), notify_progress = self.uploadProgressChanged)
self._material_sync.exportAll(QUrl.fromLocalFile(self._archive_filename), notify_progress = self.uploadProgressChanged)
http = HttpRequestManager.getInstance()
http.get(
@ -70,9 +72,11 @@ class UploadMaterialsJob(Job):
return
upload_url = response_data["upload_url"]
file_data = open(self._archive_filename, "rb").read()
http = HttpRequestManager.getInstance()
http.put(
url = upload_url,
data = file_data,
callback = self.onUploadCompleted,
error_callback = self.onError,
scope = self._scope