-
-
Notifications
You must be signed in to change notification settings - Fork 598
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest versions of Parse Server and the Parse JS SDK.
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
- Execute an aggregate query that returns a file which is not part of the class on which the query runs.
- File data is returned is only the file name, e.g.
{ file: 'abc.txt' }
. - 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