parse-community / parse-community/parse-server-s3-adapter

Objects uploaded with generateKey return incorrect locations

Open
#237 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
JavaScript
Stars
80
Forks
86
PR merge metrics
No merged PRs in 30d

Description

From parse-server\lib\Controllers\FilesController.js - line 32

const location = await this.adapter.getFileLocation(config, filename);
    await this.adapter.createFile(filename, data, contentType, options);
    return {
      url: location,
      name: filename
    };

Location is a const fed in from getFileLocation, but getFileLocation will always return the location before key generation occurs.

object location created by this.adpter.createFile as an output argument is discarded.
Additionally, getFileLocation will return the presigned item based on the old filename rather than the new file name.

Ex:

generateKey: (filename) => {
  return ${Date.now()}_${filename}; // unique prefix for every filename
}

Uploading "file.jpeg" will result in XXX.s3.amazonaws.com/file.jpeg as a key while uploading to XXX.s3.amazonaws.com/XXXX_file.jpeg

getFileLocation will return the full (optionally presignedUrl) or "https://${this._bucket}.s3.amazonaws.com/${this._bucketPrefix}${fileName}" where fileName is file.jpeg

However createFile will instead return a location of
https://${this._bucket}.s3.${this._region}.amazonaws.com/this._bucketPrefix + this._generateKey(filename)

Until this issue is fixed, generateKey should be considered to be non-functional. Either the filename should be rewritten with the generated Key prior to getFileLocation (and the createFile call should not generate a new key) or the FilesController.js should be wrapped to account for this.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/Controllers/FilesController.js around line 32 and trace getFileLocation and createFile through the adapter's generateKey path. Reproduce the file.jpeg mismatch described in the issue, then verify that the returned URL matches the location of the generated key; no test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.