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
parent
commit
6c519ec1f3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      src/asset_manager/config/config.ts
  2. 2
      src/asset_manager/view/FileUploader.ts

8
src/asset_manager/config/config.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,

2
src/asset_manager/view/FileUploader.ts

@ -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]);

Loading…
Cancel
Save