|
@@ -4,6 +4,7 @@ package handlers
|
|
|
import (
|
|
import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
+ "net/url"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/google/uuid"
|
|
@@ -84,16 +85,23 @@ func (h *UploadHandler) PresignedURL(w http.ResponseWriter, r *http.Request) {
|
|
|
policy.SetContentType(req.ContentType)
|
|
policy.SetContentType(req.ContentType)
|
|
|
policy.SetContentLengthRange(1, int64(req.MaxSizeMB)*1024*1024)
|
|
policy.SetContentLengthRange(1, int64(req.MaxSizeMB)*1024*1024)
|
|
|
|
|
|
|
|
- url, formData, err := h.minioClient.PresignedPostPolicy(r.Context(), policy)
|
|
|
|
|
|
|
+ uploadURL, formData, err := h.minioClient.PresignedPostPolicy(r.Context(), policy)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
writeError(w, http.StatusInternalServerError, "failed to generate upload URL", err)
|
|
writeError(w, http.StatusInternalServerError, "failed to generate upload URL", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Replace internal endpoint (minio:9000) with public endpoint for browser uploads
|
|
|
|
|
+ publicUploadURL := uploadURL
|
|
|
|
|
+ uploadURLStr := h.publicEndpoint + uploadURL.Path + "?" + uploadURL.RawQuery
|
|
|
|
|
+ if parsed, err := url.Parse(uploadURLStr); err == nil {
|
|
|
|
|
+ publicUploadURL = parsed
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
fileURL := h.publicEndpoint + "/" + h.bucket + "/" + objectName
|
|
fileURL := h.publicEndpoint + "/" + h.bucket + "/" + objectName
|
|
|
|
|
|
|
|
writeJSON(w, http.StatusOK, presignedURLResponse{
|
|
writeJSON(w, http.StatusOK, presignedURLResponse{
|
|
|
- UploadURL: url.String(),
|
|
|
|
|
|
|
+ UploadURL: publicUploadURL.String(),
|
|
|
FileURL: fileURL,
|
|
FileURL: fileURL,
|
|
|
Fields: formData,
|
|
Fields: formData,
|
|
|
})
|
|
})
|