Urgent.News

What's breaking now, across hundreds of outlets.

AI

Node.js AI-Generated Images in Private Object Storage with Presigned Downloads

For Node.js, the practical way to store generated images in object storage is to keep the bucket private and make the application own every access decision. In a gaming system that must retain signed documents until an explicit deletion deadline, tenant isolation matters more than a convenient image URL. Short answer: use a private object-storage bucket, persist a tenant-scoped object key and…

When generating images with Node.js, it is best practice to store them in a private object storage bucket. The application should be responsible for all access decisions. In situations where signed documents need to be retained until a specific deletion deadline, tenant isolation is more important than a convenient image URL. To implement this, store a tenant-scoped object key and deletion deadline in the database.

Generate a short-lived presigned download URL only after the application has authorized the requester. The application should own the decision about which tenant owns the object and whether it should still exist. Use unique object keys that cannot accidentally cross tenants, such as tenant/t-17/generation/g-902/result.png. Include the tenant ID, object key, content type, creation time, and deletion deadline in a single application record.

Only allow the backend to send bytes to the object storage; do not expose an upload path to the application. If a retry is needed, target the same job-specific key to avoid creating a second object under a random name. When checking an authorization request, include both tenant and object identity, check the deletion deadline, and only then pass the stored key to the adapter.

This lookup should be used by a cleanup worker to delete the object as well. While storing a URL in a player profile might be easier, it does not provide explainable deletion during an audit. The adapter should hide provider-specific calls, while the policy check should remain in application code. Define an ImageRecord type containing the tenant ID, object key, content type, and deletion deadline.

Define an ObjectStore type with methods for putting objects, presigning GET requests, and deleting objects. Implement the saveGeneratedImage function to put the generated image in the object store and insert a record into the database. Create the createDownloadUrl function to check if the record's tenant ID matches the requester tenant ID and if the deletion deadline has not passed, then return a presigned GET URL.

Keep the database adapter separate from this example, as its transaction and uniqueness rules will depend on the application database. In production, consider what it means for an object write to be successful followed by a failed database write. Implement a cleanup job to remove orphaned objects and use an outbox to make the database-to-cleanup transition observable.

Test both the successful and negative paths, ensuring that the browser can download the object directly after receiving the signed URL without making the bucket public. Implement CORS controls to allow the required origin and method for signed URLs. Measure the common failure of split writes and test the application's behavior with two tenants, expecting HTTP 403 and no presigned URL for unauthorized requests.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

How I built FixMyCity AI to turn pothole photos into repair tickets

What I Built I kept seeing potholes and piles of garbage around the city. A photo can show the problem, but someone still has to figure out where it happened, whether it was already reported, and…

  • Residents use FixMyCity app to photograph potholes and garbage
  • AI analyzes images, assigns severity ratings to issues
  • Web dashboard tracks progress of reported city maintenance issues

More from Sunday, 29 November 2026 →