Fix noms de fichiers avec symboles spéciaux
Utiliser `url.QueryUnescape()` pour s'assurer que les noms de fichiers soient bien affichés
This commit is contained in:
parent
346df72955
commit
97254e6fa1
2 changed files with 33 additions and 27 deletions
18
api/api.go
18
api/api.go
|
@ -9,6 +9,7 @@ import (
|
|||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"git.agecem.com/agecem/agecem-org/config"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -77,7 +78,11 @@ func (a *API) Call(method, route string) ([]byte, error) {
|
|||
a.Host,
|
||||
a.Port,
|
||||
)
|
||||
request := fmt.Sprintf("%s%s", endpoint, route)
|
||||
prerequest := fmt.Sprintf("%s%s", endpoint, route)
|
||||
request, err := url.QueryUnescape(prerequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch method {
|
||||
case http.MethodGet:
|
||||
|
@ -148,7 +153,7 @@ func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (
|
|||
a.Port,
|
||||
)
|
||||
|
||||
url := fmt.Sprintf("%s/v1/bucket/%s", endpoint, bucket)
|
||||
current_url := fmt.Sprintf("%s/v1/bucket/%s", endpoint, bucket)
|
||||
|
||||
// Create a new multipart writer
|
||||
body := &bytes.Buffer{}
|
||||
|
@ -161,7 +166,12 @@ func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
part, err := writer.CreateFormFile("document", file_header.Filename)
|
||||
filename_processed, err := url.QueryUnescape(file_header.Filename)
|
||||
if err != nil {
|
||||
return UploadDocumentResponse{}, fmt.Errorf("UploadDocument#url.QueryUnescape: %s", err)
|
||||
}
|
||||
|
||||
part, err := writer.CreateFormFile("document", filename_processed)
|
||||
if err != nil {
|
||||
return UploadDocumentResponse{}, fmt.Errorf("UploadDocument#writer.CreateFormFile: %s", err)
|
||||
}
|
||||
|
@ -177,7 +187,7 @@ func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (
|
|||
}
|
||||
|
||||
// Create a new HTTP request with the multipart body
|
||||
req, err := http.NewRequest(http.MethodPost, url, body)
|
||||
req, err := http.NewRequest(http.MethodPost, current_url, body)
|
||||
if err != nil {
|
||||
return UploadDocumentResponse{}, fmt.Errorf("UploadDocument#http.NewRequest: %s", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue