thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
223 stars 55 forks source link

Allow upload of files to the c8y binary storage via tedge cli #1315

Open mbay-ODW opened 2 years ago

mbay-ODW commented 2 years ago

Is your feature improvement request related to a problem? Please describe. The configuration/log plugin has implemented a logic to upload files to the binary storage of Cumulocity, However if I develop an own plugin and need to upload files to the binary storage of c8y, I currently can not do so without implementing own Rest API logic into my plugin, using the jet token etc. .

Describe the solution you'd like Since file upload logic is already available somehow in the code I would basically wish something on the cli such as:

tedge file upload c8y --file /test/filename.txt

For the cli I used the structure of the cert upload. I would basically expect to get back the binaryID of the uploaded file.

didier-wenzek commented 2 years ago

A more generic option would be to have a local HTTP proxy to the cloud endpoint, so the full REST API of Cumulocity would be available locally.

mbay-ODW commented 2 years ago

Any feedback on this here? Got the same request here now:

https://tech.forums.softwareag.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/265434/7

didier-wenzek commented 1 year ago

With the new local c8y auth proxy, we are now in good position to ease file upload to c8y.

@reubenmiller can you take some time to define a solution?

didier-wenzek commented 3 weeks ago

The proposal is to extend the tedge cli with a tedge c8y upload command, the plan being to add new Cumulocity-specific commands overtime.

Upload a file to Cumulocity

The command create a new event for the device,
attach the given file content to this new event,
and return the event ID.

Usage: tedge c8y upload [OPTIONS] --file <FILE>

Options:
      --file <FILE>
          Path to the uploaded file

      --mime-type <MIME_TYPE>
          MIME type of the file content

          [default: application/octet-stream]

      --type <EVENT_TYPE>
          Type of the event

          [default: tedge_UploadedFile]

      --text <TEXT>
          Text description of the event

          [default: ]

      --json <JSON>
          JSON fragment attached to the event

          [default: {}]

Note: The initial proposal was to add support for a tedge file upload c8y command. However, the need is more to simplify the interactions with the Cumulocity event API rather than to upload files to various targets. Hence, the decision to shift the focus toward a tedge c8y upload command.