|
@@ -3,6 +3,7 @@ package rest_http
|
|
import (
|
|
import (
|
|
"bytes"
|
|
"bytes"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "fmt"
|
|
"io"
|
|
"io"
|
|
"mime/multipart"
|
|
"mime/multipart"
|
|
"net/http"
|
|
"net/http"
|
|
@@ -61,9 +62,18 @@ func (s *RequestOut) Write(writer io.Writer) rest.IErrorArgs {
|
|
|
|
|
|
// Добавляем файлы
|
|
// Добавляем файлы
|
|
for filename, file := range files {
|
|
for filename, file := range files {
|
|
- part, err := writer.CreateFormFile("file", filename)
|
|
|
|
- if err != nil {
|
|
|
|
- return rest.ErrorMessage("ErrResponsePartFileCreate", err.Error())
|
|
|
|
|
|
+ var part io.Writer
|
|
|
|
+ if mimeFile, check := file.(*rest.MimeFile); check {
|
|
|
|
+ h := make(textproto.MIMEHeader)
|
|
|
|
+ h.Set("Content-Type", mimeFile.MimeType)
|
|
|
|
+ h.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, mimeFile.Name))
|
|
|
|
+ if part, err = writer.CreatePart(h); err != nil {
|
|
|
|
+ return rest.ErrorMessage("ErrResponsePartFileCreate", err.Error())
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if part, err = writer.CreateFormFile("file", filename); err != nil {
|
|
|
|
+ return rest.ErrorMessage("ErrResponsePartFileCreate", err.Error())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if _, err := io.Copy(part, file); err != nil {
|
|
if _, err := io.Copy(part, file); err != nil {
|
|
return rest.ErrorMessage("ErrResponsePartFileCopy", err.Error())
|
|
return rest.ErrorMessage("ErrResponsePartFileCopy", err.Error())
|