// POST /uploads — returns { id, uploadUrl } to the browser
func presignHandler(client *dreep.Client) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Authorise the signed-in user and enforce your own quotas first.
var in struct {
Filename string `json:"filename"`
ContentType string `json:"contentType"`
SizeBytes int64 `json:"sizeBytes"`
}
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
upload, err := client.PresignUpload(r.Context(), dreep.PresignOptions{
Filename: in.Filename,
ContentType: in.ContentType,
SizeBytes: in.SizeBytes,
Destination: dreep.Destination{Folder: "user-uploads"},
})
if err != nil {
http.Error(w, "could not start upload", http.StatusBadGateway)
return
}
json.NewEncoder(w).Encode(map[string]string{
"id": upload.ID,
"uploadUrl": upload.UploadURL,
})
})
}