-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Add file triggers and file meta data #6344
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
Changes from all commits
3e6de75
7ce5209
a8d404e
00a6b27
d41d035
288bb2a
c3470bb
0863e84
7d0c4e2
eecc3ff
93c9548
c22ef49
8d1576b
1c389ce
22a2699
70a4c81
370d091
c4f6bd4
663e355
5b1c0f4
14b41b3
a0087a0
d89b358
2982df9
ac5ba86
2cfe086
36222dc
0c4e191
51db0a6
221eafb
711c9fd
946014d
299135d
476052d
70f9b30
f6ddc0b
f43c26c
ffad97c
f34a8db
deea148
b7edf4b
bed35c9
859a603
cfeda1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ export class FilesController extends AdaptableController { | |
return this.adapter.getFileData(filename); | ||
} | ||
|
||
createFile(config, filename, data, contentType) { | ||
createFile(config, filename, data, contentType, options) { | ||
const extname = path.extname(filename); | ||
|
||
const hasExtension = extname.length > 0; | ||
|
@@ -31,12 +31,14 @@ export class FilesController extends AdaptableController { | |
} | ||
|
||
const location = this.adapter.getFileLocation(config, filename); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we have a problem here deciding the location prior to your hooks being called? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the same problem as described here: #6518 the location is computed before the triggers and adapters get a chance to potentially modify the file name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is currently no way to change the name of the Parse.File because there is no setter. I believe with these hooks you could create a new Parse.File (with a new name) using the same data as the original file and return it in the hook. Your new file (with the new file name) will be saved instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stevestencil Would it be possible to add a test case for this. When a client SDK asks to save file A.txt and in beforeSave you create new File with name B.txt and the same contents, verify that it is actually saved into B.txt? That would be awesome to consider this practice as a blessed way to change filename during the upload. To explain some background. Client SDK wants to save A.txt but when pushing to S3 you want to make the filename YYYY-MM-DD-A.txt so that you can later clean up files on S3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote a test case for your example and it passes. You'll just have to make sure preserveFileName is set to true in your parse-server config so that the random text does not get prepended to your file names. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry to slow this down, I can't wait to get it in and use it in production, but what happens when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other words, prepending a filename passed in from client SDK is fine IMHO, this is the default server behavior to make sure that all saved files are unique. The beforeSave trigged should get called on such file, and there if you change anything, it should still work, regardless whether the filename in beforeSave was kept intact from client SDL ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no matter if preserveFileName is true or false, the beforeSaveFile hook will get the file name as it came from the client (lets say foo.txt)... The file name gets changed by adding the random text to the beginning of the file name inside of parse-server. if you set preserveFileName to false this will not happen. So in a nutshell. The random text gets added after the beforeSaveFile hook and before the file actually saves to whatever storage solution you're using. |
||
return this.adapter.createFile(filename, data, contentType).then(() => { | ||
return Promise.resolve({ | ||
url: location, | ||
name: filename, | ||
return this.adapter | ||
.createFile(filename, data, contentType, options) | ||
.then(() => { | ||
return Promise.resolve({ | ||
url: location, | ||
name: filename, | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
deleteFile(config, filename) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.