nidus-sync/platform/file/image.go
Eli Ribble a6f9396760
Add first draft of mailer integration
This adds a bunch of stuff, including setting the organization's Lob
sender address ID, inserting mailer/compliance_report relationships,
adding external id from Lob (or maybe some other provider) and
attempting to load up the pool feature for a site.
2026-04-16 19:49:18 +00:00

34 lines
895 B
Go

package file
import (
"fmt"
"io"
"net/http"
"os"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
)
func ImageFileFromReader(collection Collection, uid uuid.UUID, body io.Reader) error {
filepath := fileContentPathUUID(collection, uid)
// Create file in configured directory
dst, err := os.Create(filepath)
if err != nil {
return fmt.Errorf("Failed to create image file %s: %w", filepath, err)
}
defer dst.Close()
// Copy rest of request body to file
_, err = io.Copy(dst, body)
if err != nil {
return fmt.Errorf("Unable to save file %s: %w", filepath, err)
}
log.Info().Str("filepath", filepath).Int("collection", int(collection)).Msg("Saved image file content to collection")
return nil
}
func ImageFileToWriter(collection Collection, uid uuid.UUID, w http.ResponseWriter) {
image_path := fileContentPathUUID(collection, uid)
writeFileContent(w, image_path)
}