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

Objects uploaded with generateKey return incorrect locations #237

Open
AdrianCurtin opened this issue Jan 9, 2025 · 3 comments
Open

Objects uploaded with generateKey return incorrect locations #237

AdrianCurtin opened this issue Jan 9, 2025 · 3 comments
Labels

Comments

@AdrianCurtin
Copy link

AdrianCurtin commented Jan 9, 2025

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.

Copy link

Thanks for opening this issue!

@mtrezza
Copy link
Member

mtrezza commented Jan 9, 2025

What version of the adapter has this issue? Did you try different versions to see where this issues started to occur?

@AdrianCurtin
Copy link
Author

AdrianCurtin commented Jan 9, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants