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

Saved filename fixed so that clients display it correctly #2415 #2705

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Controllers/FilesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export class FilesController extends AdaptableController {
contentType = mime.lookup(filename);
}

filename = randomHexString(32) + '_' + filename;
// increased the random string length to 36 so that it is the same length as an UUID with dashes.
// This makes file name property extraction for display in clients such as Parse Dashboard to work correctly.
// We can not use an UUID with dashes here because it is already used for files.parse.com hosted files and
// expandFilesInObject method below uses this distinction to construct the correct url for the file.
filename = randomHexString(36) + '_' + filename;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a real UUID instead of a random hex? (32 chars + 4 dash right?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained in the comment, if we use a UUID, expandFilesInObject method will think the file is hosted in files.parse.com and construct the wrong URL. We want to keep the support for files.parse.com files and Parse Server created files so this keeps both working.

Copy link
Contributor

@flovilmart flovilmart Sep 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you look at the regex here https://github.com/ParsePlatform/parse-server/blob/e690b73bb5982cb8c8766e92c44e09f6dcd9aa99/src/Controllers/FilesController.js#L9

the separator between the UUID and the rest of the file is a - .

IN our case we use a _ for separating the random string and the filename. So that would still work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. So I can do something like this:

var hexstring = randomHexString(32)
var uuid = hexstring.substring(0,8) + "-" + hexstring.substring(8,12) + "-" + hexstring.substring(12,16) + "-" + hexstring.substring(16,20) + "-" + hexstring.substring(20);

filename = uuid + '_' + filename;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add the uuid package to generate a true UUID. (https://github.com/broofa/node-uuid)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. will do. thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks YOU!


var location = this.adapter.getFileLocation(config, filename);
return this.adapter.createFile(filename, data, contentType).then(() => {
Expand Down