diff --git a/docs/files.md b/docs/files.md index 0f398e0304d..b7033739756 100644 --- a/docs/files.md +++ b/docs/files.md @@ -655,7 +655,7 @@ Content-Disposition: attachment; filename="project-X.zip" Content-Type: application/zip ``` -### POST /files/downloads/?Path=file_path +### POST /files/downloads?Path=file_path Create a file download. The Path query parameter specifies the file to download. The response json API links contains a `related` link for downloading the file, see below. diff --git a/web/files/files_test.go b/web/files/files_test.go index a9b8632b938..494153e56d2 100644 --- a/web/files/files_test.go +++ b/web/files/files_test.go @@ -997,6 +997,32 @@ func TestArchiveCreateAndDownload(t *testing.T) { assert.Equal(t, `attachment; filename=archive.zip`, disposition) } +func TestFileCreateAndDownload(t *testing.T) { + + body := "foo,bar" + res1, _ := upload(t, "/files/?Type=file&Name=todownload2steps", "text/plain", body, "UmfjCVWct/albVkURcJJfg==") + if !assert.Equal(t, 201, res1.StatusCode) { + return + } + + path := "/todownload2steps" + + res, err := http.Post(ts.URL+"/files/downloads?Path="+path, "", nil) + assert.NoError(t, err) + assert.Equal(t, 200, res.StatusCode) + var data map[string]interface{} + err = json.NewDecoder(res.Body).Decode(&data) + fmt.Println(&data, err) + assert.NoError(t, err) + + downloadURL := ts.URL + data["links"].(map[string]interface{})["related"].(string) + res2, err := http.Get(downloadURL) + assert.NoError(t, err) + assert.Equal(t, 200, res2.StatusCode) + disposition := res2.Header.Get("Content-Disposition") + assert.Equal(t, `attachment; filename=todownload2steps`, disposition) +} + func TestArchiveNotFound(t *testing.T) { body := bytes.NewBufferString(`{ "data": {