From 4ce97888444fc1e334e6a08c5ac2145233ef4119 Mon Sep 17 00:00:00 2001 From: jon Date: Thu, 3 Oct 2024 14:13:03 +1300 Subject: [PATCH] Allow setting the filename properly of the `file` field in the multipart upload. This allows us to work out the type of the uploaded file more easily in the streaming upload context on the API server, where other metadata may not be available at the time that the upload part is processed. --- api.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index e706461..f2ae114 100644 --- a/api.go +++ b/api.go @@ -303,8 +303,17 @@ func (api *CacophonyAPI) UploadVideo(r io.Reader, data map[string]interface{}) ( if _, ok := data["type"]; !ok { data["type"] = "thermalRaw" } + data["fileHash"] = hash + filename := "file" + value, exists := data["filename"] + if exists { + if value, ok := value.(string); ok { + filename = value + } + } + // JSON encoded "data" parameter. dataBuf, err := json.Marshal(data) if err != nil { @@ -315,7 +324,7 @@ func (api *CacophonyAPI) UploadVideo(r io.Reader, data map[string]interface{}) ( } // Add the file as a new MIME part. - fw, err := w.CreateFormFile("file", "file") + fw, err := w.CreateFormFile("file", filename) if err != nil { return 0, err }