From 426fef6e4aaa9729ea97a9e5233936a327f4163f Mon Sep 17 00:00:00 2001 From: Jack Minardi Date: Mon, 6 Apr 2015 16:45:10 -0400 Subject: [PATCH 1/2] accept arbitrary metadata at the file upload endpoint --- src/octoprint/server/api/files.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index 3cdf6a23..be7a1a42 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -214,6 +214,13 @@ def uploadGcodeFile(target): filename = fileProcessingFinished(added_file, fileManager.path_on_disk(FileDestinations.LOCAL, added_file), target) done = True + # Store any additional user data the caller may have passed. + if 'userjson' in request.values: + import json + fileManager.set_additional_metadata(FileDestinations.LOCAL, added_file, 'userjson', json.loads(request.values['userjson'])) + if 'userdata' in request.values: + fileManager.set_additional_metadata(FileDestinations.LOCAL, added_file, 'userdata', request.values['userdata']) + sdFilename = None if isinstance(filename, tuple): filename, sdFilename = filename From fb99c569855a5c7c64504e57d32c1fb545974070 Mon Sep 17 00:00:00 2001 From: Jack Minardi Date: Mon, 6 Apr 2015 16:45:29 -0400 Subject: [PATCH 2/2] document new optional form parameters --- docs/api/fileops.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/api/fileops.rst b/docs/api/fileops.rst index 4cf2e33e..37fc5619 100644 --- a/docs/api/fileops.rst +++ b/docs/api/fileops.rst @@ -219,6 +219,9 @@ Upload file to ``false``. :form print: Whether to start printing the file directly after upload (``true``) or not (``false``). If set, `select` is implicitely ``true`` as well. Optional, defaults to ``false``. + :form userdata: [Optional] An optional string that if specified will be saved along with the file as metadata. + :form userjson: [Optional] An optional string that if specified will be intepreted as json and then saved along with + the file as metadata. :statuscode 201: No error :statuscode 400: If no `file` is included in the request, or the request is otherwise invalid. :statuscode 404: If `location` is neither ``local`` nor ``sdcard`` or trying to upload to SD card and SD card support