Skip to content

fix(storage): add missing encryption/compression properties to File model with validated defaults - #12405

Merged
Meldiron merged 2 commits into
appwrite:mainfrom
deepshekhardas:fix/11647-file-encryption-property
Sep 21, 2026
Merged

Meldiron merged 2 commits into
appwrite:mainfrom
deepshekhardas:fix/11647-file-encryption-property

Conversation

@deepshekhardas

Copy link
Copy Markdown
Contributor

The File model on main was missing the \encryption\ and \compression\ properties that exist in the 1.9.x branch. When the Flutter SDK (>= 20.3.3) tries to access \ ile.encryption, it returns null instead of a boolean, causing a crash.

Changes

  • Added \encryption\ (boolean) and \compression\ (string) fields to the File model schema
  • Fixed compression default from ''\ to \Compression::NONE\ (prevents response contract violation)
  • Added \ ilter()\ method that derives compression/encryption from actual document attributes
  • Validate compression against allowed values (
    one/\gzip/\zstd)

Fixes

Closes #11647

This also addresses the code review feedback from #11652 where compression default was flagged as ''\ contradicting the documented closed set.

@greptile-apps

greptile-apps Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The PR should not merge until the explicit testing rule is satisfied and the outstanding compression dependency inconsistency is resolved.

Fix All in Claude CodeFindings

  1. P1 The filter method and the rule descriptions/defaults references Utopia\Compression\Compression from the transitive dependency utopia-php/compression , while every other file that works with the same algorithm database value - Bucket.php , Builds.php , Migrations.php , and storage.php - all import Utopia\Storage\Compression\Compression from the direct utopia-php/storage dependency. If the two classes ever diverge in their constant string values, the in array validation in filter would silently fall back to Compression NONE for compressed files, causing them to be misreported as uncompressed in API responses. Using the same class as the rest of the codebase removes this risk and keeps the import consistent. ▶
  2. P2 Test Mirrors Processing Internals ▶
Fix with agent prompt
### Issue 1
src/Appwrite/Utopia/Response/Model/File.php:undefined-7
The `filter()` method (and the rule descriptions/defaults) references `Utopia\Compression\Compression` from the transitive dependency `utopia-php/compression`, while every other file that works with the same `algorithm` database value - `Bucket.php`, `Builds.php`, `Migrations.php`, and `storage.php` - all import `Utopia\Storage\Compression\Compression` from the direct `utopia-php/storage` dependency. If the two classes ever diverge in their constant string values, the `in_array` validation in `filter()` would silently fall back to `Compression::NONE` for compressed files, causing them to be misreported as uncompressed in API responses. Using the same class as the rest of the codebase removes this risk and keeps the import consistent.

```suggestion
use Utopia\Storage\Compression\Compression;
```

### Issue 2
tests/e2e/Services/Storage/StorageBase.php:763-764
This test defines its scenario by comparing the fixture with the production `APP_STORAGE_READ_BUFFER`, then asserts the `none` and `false` values produced by that threshold-dependent processing path on lines 786–787. This mirrors source configuration and implementation details instead of isolating the stable File response contract. A threshold or fixture change can either break the test or silently redefine what it covers. The repository requires tests to verify observable behavior rather than mirror source configuration, so this must be addressed before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR restores compression and encryption metadata on Storage File responses, gives uncompressed files a valid none default, and initializes partial-upload documents consistently.

  • Adds SDK-visible compression and encryption fields derived from persisted storage metadata.
  • Uses Compression::NONE when creating partial-upload records.
  • Adds end-to-end coverage for create, retrieve, and chunked-upload responses.
  • The new chunked-upload coverage is improperly coupled to the production processing threshold.

Reviews (3) · Last reviewed commit: "fix(storage): never return an empty comp..."


use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
use Utopia\Compression\Compression;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The filter() method (and the rule descriptions/defaults) references Utopia\Compression\Compression from the transitive dependency utopia-php/compression, while every other file that works with the same algorithm database value — Bucket.php, Builds.php, Migrations.php, and storage.php — all import Utopia\Storage\Compression\Compression from the direct utopia-php/storage dependency. If the two classes ever diverge in their constant string values, the in_array validation in filter() would silently fall back to Compression::NONE for compressed files, causing them to be misreported as uncompressed in API responses. Using the same class as the rest of the codebase removes this risk and keeps the import consistent.

Suggested change
use Utopia\Compression\Compression;
use Utopia\Storage\Compression\Compression;

…alidated defaults

- Add encryption (bool) and compression (string) schema fields
- Fix compression default from empty string to Compression::NONE
- Add filter() to derive compression/encryption from document attributes
- Validate compression against allowed values (none/gzip/zstd)
- Fixes Flutter SDK crash when accessing file.encryption (issue appwrite#11647)
@Meldiron
Meldiron force-pushed the fix/11647-file-encryption-property branch from 12d2e05 to cf9a0a1 Compare September 21, 2026 11:03
@Meldiron

Copy link
Copy Markdown
Contributor

Rebased onto main.

This PR targeted main but its branch was cut from 1.9.x, so the diff was showing ~51k files and GitHub refused to render it. Rebased onto main — the File.php change applied cleanly and it's now a 1-file, +6/-2 diff and mergeable.

Closed #12524, which was the 1.9.x-targeted PR from this same branch.

The first chunk of a chunked upload created the file document with
'algorithm' => '', and Document::getAttribute() only falls back to its
default when the key is unset, so that empty string was returned as-is
in the compression property. Write Compression::NONE instead, and fall
back with ?: in the model so existing documents are covered too.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Meldiron

Copy link
Copy Markdown
Contributor

Simplified the filter and added E2E coverage.

Dropped the whitelist check — but it was load-bearing, so the underlying cause is fixed instead. Document::getAttribute() uses isset(), which only falls back to the default when the key is unset:

public function getAttribute(string $name, mixed $default = null): mixed
{
    if (isset($this[$name])) {
        return $this[$name];
    }
    return $default;
}

Files/Create.php created the file document with 'algorithm' => '' on the first chunk of a chunked upload, so getAttribute('algorithm', Compression::NONE) returned that empty string rather than none — which is what reached the SDK as an unparseable enum. The in_array guard was mapping it back to none after the fact.

So:

  • Files/Create.php now writes Compression::NONE instead of ''.
  • The model falls back with ?: rather than a default argument, which covers '' and null in one operator and keeps existing documents correct — the algorithm column is 'default' => null, 'required' => false, so both states exist in the wild.
$document->setAttribute('compression', $document->getAttribute('algorithm') ?: Compression::NONE);

E2E test in StorageBase (so it runs for client, server and console), against a bucket with neither option configured:

  • single-request upload — compression is none, encryption is true (bucket default, file under the buffer)
  • chunked upload — asserts on every chunk response, including the first, which is the one that used to carry ''

assertSame/assertTrue/assertFalse are strict, so a null or '' fails them directly.

@Meldiron
Meldiron merged commit cdb5ea0 into appwrite:main Sep 21, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File encryption property is missing

2 participants