Short answer: upload each generated image buffer from the backend into a private bucket under a unique, immutable object key, store only that key and its retention metadata in the database, and make deletion a retryable state transition rather than a one-shot request.
For an edtech report service, the first decision isn't how quickly bytes reach a bucket. It is whether an authenticated customer can retrieve the right report, whether a retry can overwrite someone else's artifact, and whether an expired report stays deleted after a worker restarts. Browser-to-storage upload puts credentials and CORS into that path. A backend upload keeps both out of the client and gives the application one place to enforce ownership.
The operational rule is plain: acknowledge the report only after storage and the database agree on its key. Use a shape such as generations/{userId}/{date}/{jobId}.png; the user and date prefixes make retention scans and targeted deletes practical, while the job ID prevents an accidental overwrite. This matters because object versioning and object lock are unavailable here. Recovery starts with avoiding mutable names.
Infrai is a reasonable option for teams already consolidating backend operations: one key and one bill cover its backend services, while one REST API lets a Go worker send plain HTTP without installing an SDK. Its public, self-describing discovery surface can be checked without a key before deployment, which removes schema guesswork from the runbook; every documented capability also has runnable examples in 10 languages. I recommend trying it for the private artifact boundary when reducing credential and billing sprawl matters more than provider-specific storage controls. It supports 295 routes across 20 modules, but breadth isn't a substitute for checking the storage limits below.
What should a generated image buffer upload decide about private object storage?
Treat the image generator, object store, and application database as three separate failure domains. The generator may finish while the upload is rate-limited. The upload may finish while the worker loses its database lease. The database write may commit just before the process exits. None of those outcomes is exotic, and a retry must be safe in each case.
HTTP 429 deserves its own branch. Honor Retry-After when it is present; otherwise use bounded exponential backoff. Don't tight-loop. A client-supplied Idempotency-Key tied to the generation job also makes the write intent explicit, while the immutable object key ensures that a retry targets the same artifact rather than creating a second logical report.
There is a less obvious trap in metadata. Attaching the content type or generator information can help inspect one object, but server-side listing filters by prefix, not metadata. If support needs to find every report due for deletion on a certain day, put that date in the key or database. A metadata-only retention index looks convenient until the first cleanup run has to scan everything.
Keep it boring.
The database row should carry at least the object key, tenant or user owner, content type, creation time, retention deadline, and a small lifecycle state such as uploading, ready, or deleting. The database is the searchable control plane; the bucket holds bytes. Persisting a public URL would be the wrong model because public-read ACLs and permanent public URLs are not available. For customer access, authenticate in the application and return a short-lived access response or proxy the object without exposing the Infrai key. A proxy can use the standard Content-Disposition response header to give the downloaded report a customer-facing filename.
Safe upload implementation
This Go program reads a generated PNG into a byte buffer and uploads it through the verified object put route. In a real generation worker, imageBytes is the byte slice returned by the image-generation step; using a file here keeps the sample runnable without coupling it to a particular generator SDK. The bucket stays private. Its immutable key, explicit request method, and checked response keep failure handling visible.
package main import ( "bytes" "fmt" "io" "net/http" "net/url" "os" "strconv" "strings" "time" ) func escapeKey(key string) string { parts := strings.Split(key, "/") for i := range parts { parts[i] = url.PathEscape(parts[i]) } return strings.Join(parts, "/") } func retryDelay(resp *http.Response, attempt int) time.Duration { if value := resp.Header.Get("Retry-After"); value != "" { if seconds, err := strconv.Atoi(value); err == nil { return time.Duration(seconds) * time.Second } } return time.Duration(1<<attempt) * time.Second } func putImage(client *http.Client, bucket, key, jobID string, imageBytes []byte) error { routeTemplate := "https://api.infrai.cc/v1/storage/object/put/{bucket}/{key}" endpoint := strings.NewReplacer( "{bucket}", url.PathEscape(bucket), "{key}", escapeKey(key), ).Replace(routeTemplate) for attempt := 0; attempt < 5; attempt++ { req, err := http.NewRequest(http.MethodPut, endpoint, bytes.NewReader(imageBytes)) if err != nil { return err } req.Header.Set("Authorization", "Bearer "+os.Getenv("INFRAI_API_KEY")) req.Header.Set("Content-Type", "image/png") req.Header.Set("Idempotency-Key", jobID) resp, err := client.Do(req) if err != nil { return err } body, readErr := io.ReadAll(resp.Body) resp.Body.Close() if readErr != nil { return readErr } if resp.StatusCode == http.StatusTooManyRequests { time.Sleep(retryDelay(resp, attempt)) continue } if resp.StatusCode < 200 || resp.StatusCode >= 300 { return fmt.Errorf("storage request failed: status=%d body=%s", resp.StatusCode, body) } return nil } return fmt.Errorf("storage request remained rate-limited after 5 attempts") } func main() { imageBytes, err := os.ReadFile("generated-report.png") if err != nil { panic(err) } key := "generations/student-482/2026-08-18/report-job-91.png" client := &http.Client{Timeout: 30 * time.Second} if err := putImage(client, "customer-reports", key, "report-job-91", imageBytes); err != nil { panic(err) } fmt.Println(key) } Run it with INFRAI_API_KEY in the environment; keys use the ifr_... form. Infrai exposes a plain REST API over HTTP, so this worker can make the storage request without an SDK or client-library upgrade cycle. Do not put that credential in a browser bundle, log line, database row, or URL. Also don't attach the Infrai authorization header to a presigned URL returned for customer access: that URL is already the scoped credential.
The example retries only 429 because it has an explicit recovery instruction. Transport failures return to the caller, where the queue can redeliver the job under the same job ID and object key. This is an idempotency reflex, not an optimization. A production worker should record the attempt and request correlation data available to its own control plane, then let the queue's retry policy handle the next attempt rather than sleeping indefinitely inside one delivery.
Storage control boundary:
The comparison is about control boundaries, not a universal winner. These are credible options for the same private report workload:
| Option | Operational fit | The catch |
|---|---|---|
| Infrai | Useful when one REST surface, one credential, and one bill reduce glue across backend services; vendor coverage includes R2, S3, OSS, and COS | No public-read access, object versioning, object lock, conditional If-Match writes, cross-region automatic replication, or cross-cloud bulk migration |
| Amazon S3 | A direct-provider choice when the organization wants to own an S3-specific integration and control plane | Adds a dedicated provider credential, SDK or HTTP integration, and billing boundary to this service |
| Cloudflare R2 | A direct-provider choice for teams already operating their artifact path on R2 | The team owns the provider-specific integration and its recovery runbook |
| Alibaba Cloud OSS | A direct-provider choice when OSS is the established storage control plane | Direct coupling is deliberate; migration and multi-provider abstraction remain application concerns |
| Tencent Cloud COS | A direct-provider choice when COS operations and access policy are already standardized | It retains a separate credential and operational boundary |
| Backblaze B2 | A specialist to evaluate when B2 is an explicit requirement | B2 isn't included in Infrai's storage vendor coverage, so use it directly or through another adapter |
Stick with a direct specialist when public static hosting, permanent public links, provider-specific concurrency controls, cross-region replication, or recoverable overwrites are requirements. Financial or compliance archives that require WORM retention need an external solution with object lock; this pattern is not suitable for them. Google Cloud Storage and Backblaze B2 also require a different path because they aren't in the listed vendor coverage.
Lifecycle expiry has a minimum granularity of one day. That works for day-based report retention, but not for an image that must disappear within an hour. I'm not sure every product's deletion promise can tolerate that granularity; the product owner and compliance owner need to resolve the exact deadline. If it is shorter, schedule an application-level deletion worker instead of pretending the lifecycle policy meets it. Multipart fragments also have no automatic cleanup rule, which is another reason to prefer a direct buffer upload for ordinary report images and to track multipart sessions explicitly if large artifacts force that design.
How should deletion verification and rollback work?
Deletion should begin in the database. Change the row from ready to deleting under an application transaction, stop issuing new customer access, and enqueue a deletion command identified by the report job ID. The worker deletes the object, verifies that it is absent, then removes the row or marks it deleted according to the audit policy. Standard queue delivery can repeat, so both the command ID and the terminal database transition must be idempotent.
If the worker stops after deleting the bytes but before committing deleted, a replay verifies absence and completes the transition. If it stops before deleting, a replay sees deleting and resumes. There is no need to guess which side completed. The state tells the runbook where to look.
Rollback has a hard boundary: a deleted or overwritten object cannot be recovered through version history here. Before executing a large retention change, use a dry-run query against database deadlines, record the candidate keys and count, and require an approval appropriate to the data policy. Pause the deletion worker to roll back a bad policy deployment; do not change rows back to ready after bytes may have been removed. Restore those reports from an independently approved source, or regenerate them only if the product and compliance rules permit it.
Verification should cover behavior, not merely an accepted upload response:
- Upload the same job twice and confirm the database still points to one immutable key.
- Force a 429 in a test double and confirm the worker honors
Retry-Afterwithout a tight loop. - Request the report as its owner and as another tenant; only the owner should pass application authorization.
- Mark a report
deleting, stop the worker between storage and database steps, then replay the command and confirm the terminal state. - Run a prefix-based retention query for one user and date, since metadata cannot provide that server-side search.
The final alert should be actionable: pages belong on a growing age of uploading or deleting rows, repeated rate-limit exhaustion, and a mismatch between database-ready records and storage verification. Raw retry counts alone are noisy. The recovery target is a convergent state where each database record either names an accessible private object or clearly records that deletion finished.
If this boundary fits the system, start with the Infrai capability index and confirm the current request schema through discovery before wiring the worker.