parse-community / parse-server-s3-adapter

AWS S3 file storage adapter for Parse Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getFileLocation does not URI encode filename in directAccess cases

rdbayer opened this issue · comments

Among other things, this can make filenames with spaces in them fail from an iOS client, for example

I don't know how the contribution process works, but I believe the fix is that the function should look like this:

S3Adapter.prototype.getFileLocation = function(config, filename) {
  var encodedFilename = encodeURIComponent(filename);
  if (this._directAccess) {
    if (this._baseUrl && this._baseUrlDirect) {
      return `${this._baseUrl}/${encodedFilename}`;
    } else if (this._baseUrl) {
      return `${this._baseUrl}/${this._bucketPrefix + encodedFilename}`;
    } else {
      return `https://${this._bucket}.s3.amazonaws.com/${this._bucketPrefix + encodedFilename}`;
    }
  }
  return (config.mount + '/files/' + config.applicationId + '/' + encodedFilename);
}

Open a pull request with the fix and the according tests.

More info on github pull requests here:
https://help.github.com/articles/about-pull-requests/

Sorry, don't have the time (or confidence, since I'm new to this code) to check it in for everyone, but it did fix issues I was having.

fixed by: #30