Suggestion T22145
Visible to All Users

File Upload - Deactivate updating the value of the file upload question on drag-drop?

created a month ago (modified a month ago)

[Ticket cloned from T20727: Change template of file upload question]

Hello, i have a follow up request.

This proposed solution works perfectly. We have discovered lately that it can be possible to upload a value to the file upload question using drag and drop, which will skip showing the dialog as proposed above using the survey.onOpenFileChooser.add(). Is there a way to deactivate updating the value of the file upload question on drag-drop?

Comments (1)

    Hello,
    I will discuss this usage scenario with our developers: https://github.com/surveyjs/survey-library/issues/9551. Please stay tuned.

    Answers approved by surveyjs Support

    created 18 days ago

    Hello,
    Our developers researched this issue. It appears that there is no simple way to prevent users from dropping files to a File Upload. If you wish to upload only those files which were selected via your custom file chooser dialog, consider sending an additional custom attribute within your uploaded files and check this attribute within the survey.onUploadFiles function.

    Let me know if you have any further questions.

      Show previous comments (4)

        Hello Sam,

        thank you for your suggestions. I can't tell if it helps or not yet. Do you mind sharing more technical information with me, like how do you handle the drag and drop files differently?

          TypeScript
          creator.onUploadFile.add( async ( _sender: CreatorBase, { files, callback }: { question: Question; files: File[]; callback: (status: string, link: string) => void } ) => { console.log('onUploadFile', files); if (files[0].name.startsWith('https://')) { callback('success', files[0].name); } else if(fileUploader) { const url = await fileUploader(files[0]); callback('success', url.toString()); } } ); creator.onOpenFileChooser.add( async ( _sender: CreatorBase, { callback }: { input: HTMLInputElement; callback: (files: File[]) => void } ) => { console.log('onOpenFileChooser'); try { const pickedFile = await pickFile(); callback([new File([], pickedFile.toString())]); } catch (error) { console.error('File picker canceled with error:', error); } } );

          Basically in the file chooser I set the file name to a URL, in the upload event I check whether the filename is a URL, if not I upload it and call the callback with the URL.

            Thank you for your suggestions sam :)

            I have a similar approach to this that i can implement. However for me it entails much more code to maintain the business case. Thats why i wanna prevent the event from triggering from the first place.