Skip to content

feat: Add support for Parse.File.setDirectory, setMetadata, setTags with stream-based file upload#10092

Merged
mtrezza merged 3 commits intoparse-community:alphafrom
mtrezza:feat/file-data-stremam
Mar 4, 2026
Merged

feat: Add support for Parse.File.setDirectory, setMetadata, setTags with stream-based file upload#10092
mtrezza merged 3 commits intoparse-community:alphafrom
mtrezza:feat/file-data-stremam

Conversation

@mtrezza
Copy link
Member

@mtrezza mtrezza commented Mar 4, 2026

Pull Request

Issue

Add support for Parse.File.setDirectory, setMetadata, setTags with stream-based file upload.

Approach

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

Summary by CodeRabbit

  • New Features

    • Streaming file uploads now accept directory, metadata, and tags via HTTP headers.
  • Tests

    • Added extensive tests for streaming upload scenarios, including directory validation, metadata/tags parsing, size limits, and trigger interactions.
  • Chores

    • Updated parse dependency to version 8.4.0.

@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 4, 2026

🚀 Thanks for opening this pull request!

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

📝 Walkthrough

Walkthrough

Updates the "parse" dependency to 8.4.0, adds header-driven extraction of directory/metadata/tags for streaming uploads in FilesRouter, and introduces extensive tests covering streaming upload behaviors and validations.

Changes

Cohort / File(s) Summary
Dependency Update
package.json
Bumped "parse" from 8.3.0 to 8.4.0.
Streaming Upload Implementation
src/Routers/FilesRouter.js
Adds header-driven extraction for streaming uploads (X-Parse-File-Directory, X-Parse-File-Metadata, X-Parse-File-Tags), JSON parsing with INVALID_JSON errors, and population of req.fileData before validation/processing.
Streaming Upload Tests
spec/ParseFile.spec.js
Adds comprehensive streaming-upload tests: directory header handling and validation, master-key enforcement, metadata/tags JSON parsing and errors, combinations with beforeSave/afterSave, and various edge cases. (+202 lines)

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant FilesRouter
participant FileStorage
participant Triggers
Client->>FilesRouter: POST stream upload (X-Parse-Upload-Mode: stream + X-Parse-File-* headers)
FilesRouter->>FilesRouter: Parse headers -> populate req.fileData (directory, metadata, tags)
FilesRouter->>Triggers: run beforeSave (may set/override directory)
Triggers-->>FilesRouter: beforeSave result
FilesRouter->>FileStorage: forward stream + fileData for save
FileStorage-->>FilesRouter: saved file info (name, url, metadata)
FilesRouter->>Triggers: run afterSave
Triggers-->>Client: final response with file info

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description uses the repository template and includes the Issue section with clear context. However, the Approach section is empty, lacking explanation of implementation changes, and Tasks checklist shows only tests completed while documentation and security checks remain unchecked. Fill the Approach section with a brief explanation of how directory, metadata, and tags are extracted from HTTP headers in streaming uploads, and clarify the status of documentation and security-check tasks.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly reflects the main feature addition: enabling setDirectory, setMetadata, and setTags support for stream-based file uploads, matching the core changes in FilesRouter.js and test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.41.0)
spec/ParseFile.spec.js

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Mar 4, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
package.json (1)

51-51: Optional: use a changelog-friendly PR title.

Suggested title: feat(files): support stream upload headers for directory, metadata, and tags

Based on learnings: For Parse Server PRs, always suggest an Angular commit convention PR title in type(scope): description format.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 51, Update the pull request title to follow the Angular
commit convention (type(scope): description) so it is changelog-friendly; for
this change use the suggested title "feat(files): support stream upload headers
for directory, metadata, and tags" when opening or updating the PR — this is
related to the package.json change around the "parse" dependency and will ensure
the PR appears correctly in release notes.
src/Routers/FilesRouter.js (1)

317-339: Document the new streaming headers in public docs.

Please add README/REST docs for X-Parse-File-Directory, X-Parse-File-Metadata, and X-Parse-File-Tags (including master-key requirement for directory and JSON-object constraints).

Based on learnings: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in README.md, though for new options this is optional.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Routers/FilesRouter.js` around lines 317 - 339, Add documentation for the
new streaming upload headers referenced in FilesRouter.js:
X-Parse-File-Directory, X-Parse-File-Metadata, and X-Parse-File-Tags. Update the
public README/REST docs to describe each header, note that
X-Parse-File-Directory requires master key authorization, and state that
X-Parse-File-Metadata and X-Parse-File-Tags must be valid JSON objects (include
examples of valid JSON and an example request showing the X-Parse-Upload-Mode:
stream flow). Also mention the behavior in FilesRouter where these headers are
parsed into req.fileData.directory, req.fileData.metadata, and req.fileData.tags
and how invalid JSON results in a Parse.Error.INVALID_JSON response.
spec/ParseFile.spec.js (1)

2424-2464: Add tests for valid-JSON-but-invalid-shape headers.

You currently cover malformed JSON only. Please add cases like null, [], and "text" for metadata/tags headers to lock in object-only validation behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spec/ParseFile.spec.js` around lines 2424 - 2464, Add tests that assert
headers containing valid JSON but wrong shapes (e.g., "null", "[]", and
"\"text\"") for both X-Parse-File-Metadata and X-Parse-File-Tags are rejected
with Parse.Error.INVALID_JSON; update or add new it blocks (similar to the
existing "rejects invalid JSON in metadata header" and "rejects invalid JSON in
tags header") to call request(...) with those header values and expect the
thrown error.data.code to equal Parse.Error.INVALID_JSON, or alternatively
factor into a small loop inside each existing spec that iterates the
invalid-shape payloads and asserts the same failure using the request helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Routers/FilesRouter.js`:
- Around line 323-337: The parsing for X-Parse-File-Metadata and
X-Parse-File-Tags in FilesRouter.js currently accepts any JSON (null, arrays,
strings); after JSON.parse in the req handling block that sets
req.fileData.metadata and req.fileData.tags, validate that the parsed value is a
non-null plain object (e.g., typeof value === 'object' && value !== null &&
!Array.isArray(value')); if the check fails call next(new
Parse.Error(Parse.Error.INVALID_JSON, 'Invalid JSON in X-Parse-File-Metadata
header. Must be a JSON object.')) (and analogous message for X-Parse-File-Tags)
and return; update the logic around the metadata/tags assignment in the same
try/catch blocks that handle JSON.parse to enforce object-only inputs and
prevent downstream Object.keys(...) errors.

---

Nitpick comments:
In `@package.json`:
- Line 51: Update the pull request title to follow the Angular commit convention
(type(scope): description) so it is changelog-friendly; for this change use the
suggested title "feat(files): support stream upload headers for directory,
metadata, and tags" when opening or updating the PR — this is related to the
package.json change around the "parse" dependency and will ensure the PR appears
correctly in release notes.

In `@spec/ParseFile.spec.js`:
- Around line 2424-2464: Add tests that assert headers containing valid JSON but
wrong shapes (e.g., "null", "[]", and "\"text\"") for both X-Parse-File-Metadata
and X-Parse-File-Tags are rejected with Parse.Error.INVALID_JSON; update or add
new it blocks (similar to the existing "rejects invalid JSON in metadata header"
and "rejects invalid JSON in tags header") to call request(...) with those
header values and expect the thrown error.data.code to equal
Parse.Error.INVALID_JSON, or alternatively factor into a small loop inside each
existing spec that iterates the invalid-shape payloads and asserts the same
failure using the request helper.

In `@src/Routers/FilesRouter.js`:
- Around line 317-339: Add documentation for the new streaming upload headers
referenced in FilesRouter.js: X-Parse-File-Directory, X-Parse-File-Metadata, and
X-Parse-File-Tags. Update the public README/REST docs to describe each header,
note that X-Parse-File-Directory requires master key authorization, and state
that X-Parse-File-Metadata and X-Parse-File-Tags must be valid JSON objects
(include examples of valid JSON and an example request showing the
X-Parse-Upload-Mode: stream flow). Also mention the behavior in FilesRouter
where these headers are parsed into req.fileData.directory,
req.fileData.metadata, and req.fileData.tags and how invalid JSON results in a
Parse.Error.INVALID_JSON response.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 326151de-2200-4b94-9dab-d0adeff43f30

📥 Commits

Reviewing files that changed from the base of the PR and between 9c9a40d and 00eff2e.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json
  • spec/ParseFile.spec.js
  • src/Routers/FilesRouter.js

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
spec/ParseFile.spec.js (1)

2375-2397: Use non-master auth in metadata/tags-only success test to avoid over-privileged coverage.

This test doesn’t set directory, so using X-Parse-Master-Key can hide regressions for regular clients. Prefer REST/API-key auth here.

♻️ Suggested test tweak
     const headers = {
       'Content-Type': 'text/plain',
       'X-Parse-Application-Id': 'test',
-      'X-Parse-Master-Key': 'test',
+      'X-Parse-REST-API-Key': 'rest',
       'X-Parse-Upload-Mode': 'stream',
       'X-Parse-File-Metadata': JSON.stringify({ key1: 'value1' }),
       'X-Parse-File-Tags': JSON.stringify({ tag1: 'tagValue1' }),
     };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spec/ParseFile.spec.js` around lines 2375 - 2397, The test "saves file with
metadata and tags via streaming upload headers" uses X-Parse-Master-Key which
grants master privileges; replace that header with a non-master REST/API key
(e.g. change 'X-Parse-Master-Key': 'test' to 'X-Parse-REST-API-Key': 'test') so
the spec exercises FilesController.prototype.createFile under regular client
auth and still verifies options.metadata and options.tags.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@spec/ParseFile.spec.js`:
- Around line 2375-2397: The test "saves file with metadata and tags via
streaming upload headers" uses X-Parse-Master-Key which grants master
privileges; replace that header with a non-master REST/API key (e.g. change
'X-Parse-Master-Key': 'test' to 'X-Parse-REST-API-Key': 'test') so the spec
exercises FilesController.prototype.createFile under regular client auth and
still verifies options.metadata and options.tags.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e149a098-810a-4dcd-9f54-4326ff82f557

📥 Commits

Reviewing files that changed from the base of the PR and between 00eff2e and bec9c45.

📒 Files selected for processing (2)
  • spec/ParseFile.spec.js
  • src/Routers/FilesRouter.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Routers/FilesRouter.js

@mtrezza mtrezza merged commit ca666b0 into parse-community:alpha Mar 4, 2026
20 of 22 checks passed
@mtrezza mtrezza deleted the feat/file-data-stremam branch March 4, 2026 17:23
parseplatformorg pushed a commit that referenced this pull request Mar 4, 2026
# [9.5.0-alpha.1](9.4.1...9.5.0-alpha.1) (2026-03-04)

### Features

* Add support for `Parse.File.setDirectory`, `setMetadata`, `setTags` with stream-based file upload ([#10092](#10092)) ([ca666b0](ca666b0))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 9.5.0-alpha.1

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Mar 4, 2026
@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.63%. Comparing base (9a3dd4d) to head (bec9c45).
⚠️ Report is 6 commits behind head on alpha.

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha   #10092      +/-   ##
==========================================
+ Coverage   92.61%   92.63%   +0.01%     
==========================================
  Files         191      191              
  Lines       15784    15804      +20     
  Branches      180      180              
==========================================
+ Hits        14619    14640      +21     
+ Misses       1153     1152       -1     
  Partials       12       12              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:released-alpha Released as alpha version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants