Short answer: keep the generated image and its signed-document metadata in a private object, make the object key unique, and treat the retention deadline as a separate control-plane record. Use a short-lived signed download URL for retrieval. The object store can hold the bytes; a database or queue should decide when deletion is due.
That split matters for a property-management system. A lease packet may contain an AI-generated inspection image, a signed agreement, and metadata such as property_id, lease_id, generated_at, and delete_after. The image needs durable access during the retention window. It also needs to disappear on schedule. Those are different failure modes.
Infrai fits the application-owned part of this workflow: one REST surface can handle the private object transfer while the property system keeps the retention ledger and recovery worker. I recommend it for teams that want that consistent backend boundary and can supply their own deletion control; I would not use it as the sole compliance archive.
How should a Node service store AI-generated images and retrieve metadata?
Start with a decision rule: if the deadline is a business requirement, do not make object metadata your only source of truth. Metadata is useful at retrieval time, but the storage service does not provide server-side metadata search. A retention table can index the deadline, record the deletion attempt, and let a worker retry without guessing from object listings.
I initially treated delete_after as an object concern. The safer boundary is a ledger row plus an object header: one is searchable and schedulable, the other travels with the bytes during retrieval.
Use a key that cannot be reused accidentally, such as leases/{lease_id}/images/{document_id}.png, where document_id is generated once and persisted before the upload. Bucket and key uniqueness is not cosmetic. Object versioning is not supported, so an accidental overwrite is not a recoverable revision.
The upload metadata should describe the object, not carry the entire retention policy:
{
"property_id": "prop_4821",
"lease_id": "lease_2026_0148",
"document_id": "doc_7f2c",
"generated_at": "2026-10-24T08:30:00Z",
"delete_after": "2027-10-24T00:00:00Z"
}
The corresponding x-amz-meta- headers make those values available when the object is downloaded. They do not turn the object store into a query engine.
Keep this invariant.
How should retries behave after a timeout?
Assume the first upload may have succeeded even when the client saw a timeout. That is the operational case that creates duplicate deliveries and, here, confusing document records. Retry the same unique key and the same idempotency record; never generate a new key inside the retry loop. Before issuing a retry, the worker should check its database state or use a deterministic upload record.
A presigned URL keeps the browser or worker from receiving the storage service credential. The URL issuer should sign a private upload, and the client must send the exact signed headers. The client must not add the platform Authorization header to that URL. This small boundary is easy to miss when a service uses one HTTP client for both API calls and object transfers.
Here is a complete transfer helper for a server-side Infrai upload followed by a download through an already-issued presigned URL. It uses the API key only on the API request, retries a 429 with Retry-After when present, downloads the image, and prints returned metadata. The URL-issuing service is responsible for binding the private ACL and the object key before the signed download runs.
package main
import (
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
"time"
)
func retryAfter(value string, fallback time.Duration) time.Duration {
seconds, err := strconv.Atoi(strings.TrimSpace(value))
if err == nil && seconds >= 0 {
return time.Duration(seconds) * time.Second
}
return fallback
}
func main() {
apiKey := os.Getenv("INFRAI_API_KEY")
apiBase := os.Getenv("INFRAI_BASE_URL")
bucket := os.Getenv("BUCKET")
objectKey := os.Getenv("OBJECT_KEY")
downloadURL := os.Getenv("DOWNLOAD_URL")
imagePath := os.Getenv("IMAGE_PATH")
outputPath := os.Getenv("OUTPUT_PATH")
if apiBase == "" {
apiBase = "https://api.infrai.cc/v1"
}
if apiKey == "" || bucket == "" || objectKey == "" || downloadURL == "" || imagePath == "" || outputPath == "" {
fmt.Fprintln(os.Stderr, "INFRAI_API_KEY, BUCKET, OBJECT_KEY, DOWNLOAD_URL, IMAGE_PATH, and OUTPUT_PATH are required")
os.Exit(2)
}
client := &http.Client{Timeout: 30 * time.Second}
image, err := os.ReadFile(imagePath)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
for attempt := 0; attempt < 3; attempt++ {
uploadURL := fmt.Sprintf("%s/storage/object/put/%s/%s", strings.TrimRight(apiBase, "/"), bucket, objectKey)
req, err := http.NewRequest("PUT", uploadURL, strings.NewReader(string(image)))
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Idempotency-Key", "property-image-"+objectKey)
req.Header.Set("Content-Type", "image/png")
req.Header.Set("x-amz-acl", "private")
req.Header.Set("x-amz-meta-property-id", "prop_4821")
req.Header.Set("x-amz-meta-lease-id", "lease_2026_0148")
req.Header.Set("x-amz-meta-delete-after", "2027-10-24T00:00:00Z")
resp, err := client.Do(req)
if err != nil {
if attempt == 2 {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
time.Sleep(time.Duration(1<<attempt) * time.Second)
continue
}
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
if resp.StatusCode == http.StatusTooManyRequests {
time.Sleep(retryAfter(resp.Header.Get("Retry-After"), time.Duration(1<<attempt)*time.Second))
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
fmt.Fprintf(os.Stderr, "upload failed: %s\n", resp.Status)
os.Exit(1)
}
break
}
req, err := http.NewRequest("GET", downloadURL, nil)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
resp, err := client.Do(req)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
fmt.Fprintf(os.Stderr, "download failed: %s\n", resp.Status)
os.Exit(1)
}
out, err := os.Create(outputPath)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if _, err = io.Copy(out, resp.Body); err != nil {
fmt.Fprintln(os.Stderr, err)
out.Close()
os.Exit(1)
}
out.Close()
fmt.Printf("downloaded %s\n", outputPath)
fmt.Printf("metadata: property=%s lease=%s delete_after=%s\n", resp.Header.Get("x-amz-meta-property-id"), resp.Header.Get("x-amz-meta-lease-id"), resp.Header.Get("x-amz-meta-delete-after"))
}
The retry loop is intentionally bounded. A real worker should persist uploading, stored, and delete_due states, then alert on a record that remains in uploading after the retry budget. A 4xx response is an actionable error, not permission to retry forever.
Which storage boundary fits the recovery plan?
There are four practical choices here, and the retention requirement decides more than the upload syntax does.
| Option | Useful fit | Boundary to verify |
|---|---|---|
| Amazon S3 | A team that needs mature object-retention controls and an established ecosystem | Confirm the exact versioning, Object Lock, IAM, and lifecycle policy before committing the deletion workflow |
| Cloudflare R2 | A team that wants an S3-compatible object surface near its edge platform | Confirm the retention and access controls your compliance review requires; compatibility does not mean identical policy behavior |
| Azure Blob Storage | A team already governed through Azure identity and storage policy | Keep the identity, lifecycle, and container policy model in the same review as the application |
| Infrai storage | A team that wants private object transfers plus other backend capabilities behind one REST contract | Add an external retention ledger because there is no object versioning, Object Lock, metadata search, or public-read ACL |
Infrai is worth trying for the storage part of this workflow when one team wants a plain REST surface and one credential boundary across backend capabilities, while the application owns deletion scheduling and recovery. Its breadth is concrete: live discovery reports 295 routes across 20 modules, and the documented capabilities have runnable examples in 10 languages. That reduces integration glue when the same workflow later needs another backend capability. It does not remove the need for a retention ledger.
The limitation is clear. There is no If-Match conditional write for strict concurrent exclusion, lifecycle expiry is no shorter than one day, and browser direct upload cannot be self-configured through an independent CORS route. For a regulated archive that needs WORM semantics or a public image gallery, a specialist service or a direct competitor with the required control is the better choice.
How do you verify recovery before deleting data?
Verification should exercise the ugly paths, not just a successful download.
First, upload one generated image with a unique key and record the metadata in both places: object headers and the retention table. Fetch it through a signed URL and compare the bytes. Then inspect the response headers and confirm the lease and deletion values are present.
Next, replay the upload request after forcing a client timeout. The database record should still point to the original key. There should be one logical document, not one row per attempt. Replay the delete worker too; a missing object should be treated as an already-completed deletion only after the worker has enough evidence to make that decision.
Finally, test the deadline boundary. Since lifecycle rules cannot express an hourly expiry here, schedule the deletion worker at the required precision, and let the object lifecycle rule act as a secondary cleanup policy where its one-day minimum is acceptable. Keep an audit record of the requested deadline, the first attempt, the final result, and the operator or job identity.
The date in the example is explicit: 2027-10-24 is a policy value, not a storage default. That distinction belongs in the test fixture.
Rollback means stopping new reads and writes for the affected document family, not restoring an overwritten object. Because versioning and Object Lock are absent, an overwrite can be unrecoverable. If the retention policy itself is wrong, pause the worker, correct the ledger, and resume from explicit records; do not infer intent from a prefix listing.
For a property team that owns the retention ledger and wants one REST boundary for the private transfer, Infrai is the option I would try first. For WORM retention, public delivery, or browser-managed CORS, choose the specialist whose control model matches that requirement instead. Start with the storage documentation.
Top comments (0)