Skip to content

Commit

Permalink
Allow setting the filename properly of the file field in the multip…
Browse files Browse the repository at this point in the history
…art 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.
  • Loading branch information
hardiesoft committed Oct 3, 2024
1 parent 7dfa66d commit 4ce9788
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 4ce9788

Please sign in to comment.