Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot restore Parse.File from aggregation query result #1456

Open
4 tasks done
mtrezza opened this issue Mar 20, 2022 · 0 comments
Open
4 tasks done

Cannot restore Parse.File from aggregation query result #1456

mtrezza opened this issue Mar 20, 2022 · 0 comments
Labels
bounty:$50 Bounty applies for fixing this issue (Parse Bounty Program) type:feature New feature or improvement of existing feature

Comments

@mtrezza
Copy link
Member

mtrezza commented Mar 20, 2022

New Issue Checklist

Issue Description

A Parse.File is stored in the DB as only the filename. When retrieving raw data from the DB (e.g. via a MongoDB aggregation query), the file data is in some cases not - and cannot be reliably be - parsed by the Parse Server internals. This means that instead of a valid Parse.File, the only file data available is the filename, e.g. abc.txt. To convert this into a valid Parse.File with Parse.File.fromJSON(...), the URL needs to be provided as well. The URL is however is composed by the Parse Server storage adapter.

Effectively that means it's not possible to easily recreate a Parse.File from aggregate query data. At least in Cloud Code, it should be possible to easily recreate the URL without having to manually access the storage adapter's getFileLocation method.

Steps to reproduce

  1. Execute an aggregate query that returns a file which is not part of the class on which the query runs.
  2. File data is returned is only the file name, e.g. { file: 'abc.txt' }.
  3. The file URL is unknown, so Parse.File.fromJSON(...) cannot be used to recreate an already saved file.

#Actual Outcome
A file URL has to be composed by manually accessing the storage adapter.

Expected Outcome

Parse.File should provide a method that auto-composes the URL, for example:

let json = {
  "__type": "File",
  "name": "abc.txt",
}
const file = Parse.File.fromJSON(json, undefined, undefined, { composeUrl: true });

json = file.toJSON();

/*
json == {
  "__type": "File",
  "name": "abc.txt",
  "url": "https://localhost:1337/parse/files/appId/abc.txt"
}
*/

Alternative

Parse Server could parse the query results for specific markers to substitute an occurrence of a raw file object with an actual Parse.File object. But that may cause conceptual issues, see parse-community/parse-server#7868.

Hack

Return the file name with a key of a file field of the same class on which the aggregation query runs. This will make Parse Server convert it to a Parse File because the schema demands so. That hack may break anytime though.

Environment

Server

  • Parse Server version: 5.1.1

Client

  • Parse JS SDK version: 3.4.1

Logs

n/a

@mtrezza mtrezza added the type:feature New feature or improvement of existing feature label Mar 20, 2022
@mtrezza mtrezza added the bounty:$50 Bounty applies for fixing this issue (Parse Bounty Program) label May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty:$50 Bounty applies for fixing this issue (Parse Bounty Program) type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

1 participant