feat: allows local update api to replace existing files with newly uploaded ones
This commit is contained in:
@@ -162,6 +162,11 @@ const result = await payload.update({
|
||||
// a file directly through the Local API by providing
|
||||
// its full, absolute file path.
|
||||
filePath: path.resolve(__dirname, './path-to-image.jpg'),
|
||||
|
||||
// If you are uploading a file and would like to replace
|
||||
// the existing file instead of generating a new filename,
|
||||
// you can set the following property to `true`
|
||||
overwriteExistingFiles: true,
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ export type Options = {
|
||||
overrideAccess?: boolean
|
||||
showHiddenFields?: boolean
|
||||
filePath?: string
|
||||
overwriteExistingFiles?: boolean
|
||||
}
|
||||
|
||||
export default async function update(options: Options): Promise<Document> {
|
||||
@@ -26,6 +27,7 @@ export default async function update(options: Options): Promise<Document> {
|
||||
overrideAccess = true,
|
||||
showHiddenFields,
|
||||
filePath,
|
||||
overwriteExistingFiles = false,
|
||||
} = options;
|
||||
|
||||
const collection = this.collections[collectionSlug];
|
||||
@@ -37,6 +39,7 @@ export default async function update(options: Options): Promise<Document> {
|
||||
overrideAccess,
|
||||
id,
|
||||
showHiddenFields,
|
||||
overwriteExistingFiles,
|
||||
req: {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
|
||||
@@ -27,6 +27,7 @@ export type Arguments = {
|
||||
disableVerificationEmail?: boolean
|
||||
overrideAccess?: boolean
|
||||
showHiddenFields?: boolean
|
||||
overwriteExistingFiles?: boolean
|
||||
}
|
||||
|
||||
async function update(incomingArgs: Arguments): Promise<Document> {
|
||||
@@ -60,6 +61,7 @@ async function update(incomingArgs: Arguments): Promise<Document> {
|
||||
},
|
||||
overrideAccess,
|
||||
showHiddenFields,
|
||||
overwriteExistingFiles = false,
|
||||
} = args;
|
||||
|
||||
if (!id) {
|
||||
@@ -135,7 +137,7 @@ async function update(incomingArgs: Arguments): Promise<Document> {
|
||||
const file = ((req.files && req.files.file) ? req.files.file : req.file) as UploadedFile;
|
||||
|
||||
if (file) {
|
||||
const fsSafeName = await getSafeFilename(staticPath, file.name);
|
||||
const fsSafeName = overwriteExistingFiles ? await getSafeFilename(staticPath, file.name) : file.name;
|
||||
|
||||
try {
|
||||
if (!disableLocalStorage) {
|
||||
|
||||
Reference in New Issue
Block a user