feature/bug
If I try to add the same file (or simply a file with the same name) to a multiple files question there's is no way to identify this situation. Problem actually rise when try to delete one of the file: _onClearFiles_ callback receive filename so you end up to delete all files with that name
I think that totally preventing this is acceptable: you cannot add files with the same name to the same question. This would solve. Otherwise, in order to run custom checks, I would need to receive question context (along with its current value) in _onUploadFiles_ callback which may be more complex
try to add the same file in two different steps (which does not make any sense but you can) and then remove one of them
https://plnkr.co/edit/W7dl9NtGVxrfzApgSaUJ?p=preview
The onUploadFiles event handler makes a callback to your server side. The server-side method can rename passed file (e.g. to GUID as we do in our surveyjs.io service) and pass this GUID to the client side. Thus instead of content: 'path/to/' + file.name will be something like content: 'path/to/' + fileUniqueID. During the clear operation this fileUniqueID will be used to address exactly this file in a server storage.
This is how we solve the task of processing files with the same name in our service (https://surveyjsio-stage.azurewebsites.net/create-survey/)
yes I also add a timestamp as suffix to the filename. But even if you rename the returned content when you clear only one of the uploaded homonym files, surveyJS will remove both. In the following plunk the content is renamed so if you try to upload the same file twice the content is different but the filename is still the same. So if you try to delete only one file both will be deleted.
https://plnkr.co/edit/mAdmMiadZwFRDtSqwRER?p=preview
Sorry if I am still missing something
No, we rename every file posted on our server and return both file name and file guid. In the content we use the guid. Thus every uploaded file has the unique id.
We change file name to guid in our server side storage and address the file by this guid.
so at line 35 of the last plunk returned _file_ prop already has the guid name?
yes, exactly
My storage service (minio/s3) returns 204, so no way to return the actual stored file. At the same time the Javascript File object received as param from the browser is only read, cannot change the name property. I would need a way to build on-the-fly a new Javascript File object with the right name. Any suggestion?
You don't need to create a real File object to pass a result.
Instead of
const newFilename = (new Date).getTime().toString() + file.name
return {
file: new File([file], newFilename, { type: file.type }),
content: 'path/to/' + newFilename
};
you can write
const newFilename = (new Date).getTime().toString() + file.name
return {
file: ( name: newFilename, type: file.type }),
content: 'path/to/' + newFilename
};
Most helpful comment
You don't need to create a real File object to pass a result.
Instead of
you can write