thin-edge / thin-edge.io

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

add filename when uploading files to Cumulocity IoT #2763

Closed reubenmiller closed 5 months ago

reubenmiller commented 7 months ago

Is your feature improvement request related to a problem? Please describe.

When files are uploaded to Cumulocity from thin-edge.io, the files do not included meta information like the filename. This results in a suboptimal user experience when the user downloads the file from the UI, as the downloaded file will automatically get the filename set to the event id (as the filename was not provided when the file was uploaded).

The file upload is used in the following thin-edge.io features:

Here is a screenshot showing that when the user clicks on the "download" button on the events page, that the downloaded filename is set to the event id (which is not helpful to the user)

image

In comparison, when the filename is set, then it is used when downloading from the UI (the file was uploaded using go-c8y-cli):

image

Describe the solution you'd like

Set the filename when uploading a file to the Cumulocity Event Attachment API.

This can be achieved by using a multipart/form-data request, where the Content-Disposition header includes meta information about the filename that is being uploaded.

For example, the data.txt file is uploaded (attached) to the Cumulocity IoT event id 36200 using the following go-c8y-cli command (which shows the multipart/form-data request as a HTTP dump):

$ c8y events createBinary --id 36200 --file $HOME/tmp/data.txt --dry --dryFormat dump
POST /event/events/36200/binaries HTTP/1.1
Host: example.c8y.io
Accept: application/json
Authorization: Bearer <token>
Content-Type: multipart/form-data; boundary=1159266905bce6f9491acf392d3df53b87c05b35dd797fdf289ecf62043d

--1159266905bce6f9491acf392d3df53b87c05b35dd797fdf289ecf62043d
Content-Disposition: form-data; name="file"; filename="data.txt"
Content-Type: application/octet-stream

foo
bar

--1159266905bce6f9491acf392d3df53b87c05b35dd797fdf289ecf62043d--

Filename convention

The filename should also include some information about the device it is coming from (to make it easier for users to compare files from multiple devices). The following filename format is proposed:

<external_id>_<filename>

Where <external_id> is the @id name of the device/service related to the operation/command where the file is coming from, e.g. mygateway:device:child01 or mygateway.

Describe alternatives you've considered

Additional context

rina23q commented 6 months ago

Code change is done by the PR #2811 Next improvements are captured in the ticket #2823

gligorisaev commented 6 months ago

QA has thoroughly checked the feature and here are the results: