mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-10 14:11:42 +00:00
[MNT-25274] Fixed issue while uploading files with multi-valued properties (#11182)
* [MNT-25274] Fixed issue while uploading files with multi-valued properties * [MNT-25274] set a more specific type
This commit is contained in:
committed by
GitHub
parent
e7024d1970
commit
923feccdb9
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { isConstructor, getQueryParamsWithCustomEncoder, removeNilValues } from './alfresco-api.utils';
|
||||
import { isConstructor, getQueryParamsWithCustomEncoder, removeNilValues, convertObjectToFormData } from './alfresco-api.utils';
|
||||
|
||||
describe('AlfrescoApiUtils', () => {
|
||||
describe('isConstructor', () => {
|
||||
@@ -93,4 +93,30 @@ describe('AlfrescoApiUtils', () => {
|
||||
expect(actual?.getAll('key2')).toEqual(['value2', 'value3']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertObjectToFormData', () => {
|
||||
it('should create correct FormData entries for string values', () => {
|
||||
const testParams: Record<string, string> = { name: 'file name', description: 'file description' };
|
||||
const result = convertObjectToFormData(testParams);
|
||||
|
||||
expect(result.get('name')).toBe('file name');
|
||||
expect(result.get('description')).toBe('file description');
|
||||
});
|
||||
|
||||
it('should handle Blob files correctly', () => {
|
||||
const testFile = new File(['content'], 'test.txt', { type: 'text/plain' });
|
||||
const testParams: Record<string, Blob> = { file: testFile };
|
||||
|
||||
const result = convertObjectToFormData(testParams);
|
||||
expect(result.get('file')).toEqual(testFile);
|
||||
});
|
||||
|
||||
it('should create multiple entries with same key for arrays', () => {
|
||||
const testParams: Record<string, Array<string>> = { categories: ['category1', 'category2', 'category3'] };
|
||||
const result = convertObjectToFormData(testParams);
|
||||
|
||||
const values = result.getAll('categories');
|
||||
expect(values).toEqual(['category1', 'category2', 'category3']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -85,7 +85,7 @@ export const removeNilValues = (obj: Record<string | number, unknown>) => {
|
||||
}, {});
|
||||
};
|
||||
|
||||
export const convertObjectToFormData = (formParams: Record<string | number, string | Blob>): FormData => {
|
||||
export const convertObjectToFormData = (formParams: Record<string | number, string | Blob | Array<string | Blob>>): FormData => {
|
||||
const formData = new FormData();
|
||||
|
||||
for (const key in formParams) {
|
||||
@@ -93,6 +93,8 @@ export const convertObjectToFormData = (formParams: Record<string | number, stri
|
||||
const value = formParams[key];
|
||||
if (value instanceof File) {
|
||||
formData.append(key, value, value.name);
|
||||
} else if (Array.isArray(value)) {
|
||||
value.forEach((item) => formData.append(key, item));
|
||||
} else {
|
||||
formData.append(key, value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user