This commit is contained in:
2026-02-13 17:30:39 +01:00
parent 20e90ec240
commit fb9bb2fc82
7 changed files with 149 additions and 16 deletions

View File

@@ -289,7 +289,8 @@ func (s *Server) HandleUpload(w http.ResponseWriter, r *http.Request) {
timestamp := time.Now().Format("2006-01-02_15:04:05")
if client.StorageType == "s3" {
// Check if S3 backend is available for S3 storage type
if client.StorageType == "s3" && s.s3Backend != nil {
// S3 upload
storageKey := fmt.Sprintf("%s/%s_%s.zfs", req.ClientID, req.DatasetName, timestamp)
if req.Compressed {
@@ -303,6 +304,12 @@ func (s *Server) HandleUpload(w http.ResponseWriter, r *http.Request) {
StorageKey: storageKey,
UploadURL: fmt.Sprintf("/upload-stream/%s", req.ClientID),
})
} else if client.StorageType == "s3" && s.s3Backend == nil {
// S3 requested but not configured
respondJSON(w, http.StatusInternalServerError, UploadResponse{
Success: false,
Message: "S3 storage requested but S3 backend is not configured on server",
})
} else {
// Local ZFS receive
snapshotName := fmt.Sprintf("%s@%s_%s", client.Dataset, req.ClientID, timestamp)
@@ -346,9 +353,17 @@ func (s *Server) HandleUploadStream(w http.ResponseWriter, r *http.Request) {
ctx := context.Background()
// Upload to S3
// When using chunked transfer (io.Pipe), ContentLength is -1
// MinIO requires -1 for unknown size to use streaming upload
size := r.ContentLength
if size < 0 {
size = 0
size = -1 // Use streaming upload for unknown size
}
if s.s3Backend == nil {
log.Printf("Error: S3 backend not initialized")
http.Error(w, "S3 backend not configured", http.StatusInternalServerError)
return
}
if err := s.s3Backend.Upload(ctx, storageKey, r.Body, size); err != nil {