Browse Source
AssetManager: Configurable upload name suffix for multi file uploads (#5672)
add multiUploadSuffix config to AssetManager
pull/5678/head
Merlin Schumacher
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
8 additions and
2 deletions
-
src/asset_manager/config/config.ts
-
src/asset_manager/view/FileUploader.ts
|
|
|
@ -46,10 +46,15 @@ export interface AssetManagerConfig { |
|
|
|
*/ |
|
|
|
credentials?: RequestCredentials; |
|
|
|
/** |
|
|
|
* Allow uploading multiple files per request. If disabled filename will not have '[]' appended. |
|
|
|
* Allow uploading multiple files per request. If disabled filename will not have the 'multiUploadSuffix' appended. |
|
|
|
* @default true |
|
|
|
*/ |
|
|
|
multiUpload?: boolean; |
|
|
|
/** |
|
|
|
* The suffix to append to 'uploadName' when 'multiUpload' is true. |
|
|
|
* @default '[]' |
|
|
|
*/ |
|
|
|
multiUploadSuffix?: string; |
|
|
|
/** |
|
|
|
* If true, tries to add automatically uploaded assets. To make it work the server should respond with a JSON containing assets in a data key, eg: |
|
|
|
* { data: [ 'https://.../image.png', {src: 'https://.../image2.png'} ] |
|
|
|
@ -146,6 +151,7 @@ const config: AssetManagerConfig = { |
|
|
|
params: {}, |
|
|
|
credentials: 'include', |
|
|
|
multiUpload: true, |
|
|
|
multiUploadSuffix: '[]', |
|
|
|
autoAdd: true, |
|
|
|
customFetch: undefined, |
|
|
|
uploadFile: undefined, |
|
|
|
|
|
|
|
@ -155,7 +155,7 @@ export default class FileUploaderView extends View { |
|
|
|
|
|
|
|
if (this.multiUpload) { |
|
|
|
for (let i = 0; i < files.length; i++) { |
|
|
|
body.append(`${config.uploadName}[]`, files[i]); |
|
|
|
body.append(`${config.uploadName}${config.multiUploadSuffix}`, files[i]); |
|
|
|
} |
|
|
|
} else if (files.length) { |
|
|
|
body.append(config.uploadName!, files[0]); |
|
|
|
|