parse-community / parse-community/parse-server-s3-adapter
Allow generateKey to be asynchronous and validate the key it returns
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 80
- Forks
- 86
- PR merge metrics
- No merged PRs in 30d
Description
New Issue Checklist
- Report security issues confidentially.
- Any contribution is under this license.
- Before posting search existing issues.
Current Limitation
generateKey is called synchronously and its return value is used unchecked:
if (this._generateKey instanceof Function) {
params.Key = this._bucketPrefix + this._generateKey(filename);
}
Two consequences:
- A key cannot be derived from anything asynchronous. Returning a promise stores the file under a key like
test/[object Promise], since the value is concatenated as-is. Anything requiring a lookup, for example resolving a tenant to a folder, cannot be expressed. - A bad return value fails late and unhelpfully. Returning
undefinedstores the file undertest/undefined. Returning a key longer than the S3 limit of 1024 UTF-8 bytes fails at S3 with an error that does not identify which part of the key was too long. In both cases the upload appears to have been accepted by the adapter.
The generator also only receives the filename, so a key cannot take the content type or the upload options into account.
Feature / Enhancement Description
Await the generator so it may be synchronous or asynchronous, pass it the content type and options, and validate its result before use: a non-empty string whose length including bucketPrefix is within the S3 key limit.
Example Use Case
- An app stores files per tenant, and the tenant's folder comes from a lookup.
generateKeyis declaredasyncand resolves the folder before returning the key.- The adapter awaits it and stores the object under the resolved key.
Alternatives / Workarounds
Precompute every possible key and hold it in memory, or move naming to the client with preserveFileName, which gives up server-side control of the key.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the generateKey call in the upload path shown in the issue and trace how its return value becomes params.Key. Update the behavior so synchronous and asynchronous generators receive the stated arguments and invalid or oversized keys are rejected before upload; done means the resolved key is used and validation errors identify the adapter failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100