Skip to content
Snippets Groups Projects
Commit 96d6e98a authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6730 return raw file on download

parent d7f1ae45
Branches
Tags
No related merge requests found
...@@ -45,7 +45,6 @@ const ( ...@@ -45,7 +45,6 @@ const (
fileFormKey = "file" fileFormKey = "file"
vorgangIdFormKey = "vorgangId" vorgangIdFormKey = "vorgangId"
contentTypeHeaderKey = "Content-Type" contentTypeHeaderKey = "Content-Type"
contentDispositionHeaderKey = "Content-Disposition"
maxFileSizeInMB = 150 maxFileSizeInMB = 150
fileChunkSizeInByte = 1024 * 1024 fileChunkSizeInByte = 1024 * 1024
) )
...@@ -210,7 +209,10 @@ func getFileHandler(w http.ResponseWriter, r *http.Request, vars map[string]stri ...@@ -210,7 +209,10 @@ func getFileHandler(w http.ResponseWriter, r *http.Request, vars map[string]stri
return return
} }
err = writeMultipartResponse(w, fileBuffer) w.Header().Set(contentTypeHeaderKey, "application/octet-stream")
w.WriteHeader(http.StatusOK)
_, err = fileBuffer.WriteTo(w)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
} }
...@@ -251,30 +253,6 @@ func fetchFileFromGrpc(ctx context.Context, fileId string, grpcAddress string) ( ...@@ -251,30 +253,6 @@ func fetchFileFromGrpc(ctx context.Context, fileId string, grpcAddress string) (
return &fileBuffer, nil return &fileBuffer, nil
} }
func writeMultipartResponse(w http.ResponseWriter, fileBuffer *bytes.Buffer) error {
w.Header().Set(contentTypeHeaderKey, "application/octet-stream")
w.Header().Set(contentDispositionHeaderKey, `attachment; filename="file"`)
w.WriteHeader(http.StatusOK)
mw := multipart.NewWriter(w)
part, err := mw.CreateFormFile(fileFormKey, fileFormKey)
if err != nil {
return fmt.Errorf("error creating multipart form file")
}
_, err = fileBuffer.WriteTo(part)
if err != nil {
return fmt.Errorf("error writing file data to multipart")
}
err = mw.Close()
if err != nil {
return fmt.Errorf("error closing multipart writer")
}
return nil
}
func ErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error) { func ErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, r *http.Request, err error) {
st, ok := status.FromError(err) st, ok := status.FromError(err)
if !ok { if !ok {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment