Skip to content

How should my app choose filenames for generated-result downloads?

Generate download filenames from trusted application metadata and a validated media type, not directly from prompts or raw upstream headers. Keep attachment names separate from filesystem paths. A useful filename can identify the project and version without embedding private prompt text, path separators or control characters.

PROTECT API ACCESS AND RESULTSAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Choose a stable naming pattern; Serialize headers correctly; Test hostile and awkward names.
Workflow diagram: Choose a stable naming pattern → Serialize headers correctly → Test hostile and awkward names. Read the article for evidence and limits.

A filename crosses several parsers

The same name may pass through an HTTP header, browser download dialog, archive and local filesystem. Quoting rules, Unicode handling and reserved characters differ. Use a conservative naming policy and preserve richer display titles separately in the application.

What to do next

  1. 01

    Choose a stable naming pattern

    Use a short safe project label, immutable attempt or asset identifier and an extension based on validated content type. Avoid secrets, email addresses and full creative prompts, which may travel into shared folders or screenshots.

  2. 02

    Serialize headers correctly

    Use a reviewed Content-Disposition implementation for attachment naming, including non-ASCII support if required. Strip control characters and path components, and never concatenate a raw user title into an HTTP header or server path.

  3. 03

    Test hostile and awkward names

    Try line breaks, quotes, slashes, emoji, very long titles and reserved-looking names in local tests. Verify the downloaded bytes remain correct, the header is valid and archive extraction cannot create unintended paths.

A concrete example

Illustrative example: a project titled Spring / Summer: draft becomes a safe attachment such as spring-summer-a17.png. The richer project title remains visible in the app, while the filesystem name avoids path interpretation.

Before you call it ready

  • Extensions match validated media types.
  • Control characters never enter headers.
  • Server paths use generated identifiers.

A locally executed, reproducible check

Windows and POSIX path rules disagree about backslashes in a proposed filename.

We executed this exact synthetic fixture on November 16, 2026 with Python 3.12.10 and SQLite 3.49.1. It ran locally with no network requests, account data or model generation. The recorded output below is an observation from that environment, not a platform benchmark. Copy the code into a separate Python file to repeat it in a suitable local environment; compare the mechanism and check your runtime version.

python
from pathlib import PurePosixPath,PureWindowsPath
candidate=r'..\private\result.png'
print('POSIX name:',PurePosixPath(candidate).name)
print('Windows name:',PureWindowsPath(candidate).name)
print('POSIX parts:',PurePosixPath(candidate).parts)
print('Windows parts:',PureWindowsPath(candidate).parts)

Recorded output and interpretation

This is a parsing contrast, not a complete safe-filename implementation. Use a generated basename and separately control the filesystem destination and HTTP header encoding. Removing traversal syntax alone does not address reserved names, controls, collisions or misleading extensions.

A matching local output establishes only the illustrated library or database behavior under these inputs. It does not certify a production integration. Preserve the approved action, authorization boundaries and current AISwapLab request contract when applying the idea.

text
POSIX name: ..\private\result.png
Windows name: result.png
POSIX parts: ('..\\private\\result.png',)
Windows parts: ('..', 'private', 'result.png')

When to stop or choose another method

Stop using raw prompt text or an unvalidated response filename as an attachment header or filesystem destination.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation