phacility/phabricator · error · Exception

You must save a file before you can generate a view URI.

Error message

You must save a file before you can generate a view URI.

What it means

Raised in PhabricatorFile::getViewURI() when the file object has no PHID, i.e. it was never saved to the database. A view/cdn URI can only be generated for a persisted file, so unsaved instances throw.

Solutions

  1. Call save() on the file before requesting its view URI
  2. Restructure code to build URIs only for persisted files
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/applications/files/storage/PhabricatorFile.php:830 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/dc04cfef2015d5f5. Report an issue: GitHub.

Appendix: source

Thrown at src/applications/files/storage/PhabricatorFile.php:830

    $format = $this->newStorageFormat();

    $iterator = $engine->getRawFileDataIterator(
      $this,
      $begin,
      $end,
      $format);

    return $iterator;
  }

  public function getURI() {
    return $this->getInfoURI();
  }

  public function getViewURI() {
    if (!$this->getPHID()) {
      throw new Exception(
        pht('You must save a file before you can generate a view URI.'));
    }

    return $this->getCDNURI('data');
  }

  public function getCDNURI($request_kind) {
    if (($request_kind !== 'data') &&
        ($request_kind !== 'download')) {
      throw new Exception(
        pht(
          'Unknown file content request kind "%s".',
          $request_kind));
    }

    $name = self::normalizeFileName($this->getName());
    $name = phutil_escape_uri($name);

View on GitHub (pinned to 5720a38cfe)