sudomakes/backroad

Request to Add Support for More File Types to the fileUpload Component

Closed this issue · 10 comments

The current fileUpload component only supports image uploads. If the component's functionality could be expanded to support a wider range of file types, such as xlsx, csv, etc., I would be very grateful.:)

I don't think that's the case, you should be able to specify your own file extensions of choice, just like how you do in html file inputs, if that doesn't work let me know and someone can work on fixing it.

Ah I see, there is an option to pass file extensions to the component but the actual extension is hard coded in the component

https://github.com/sudomakes/backroad/blob/7df10d5b32c728e97832a8e3ad8f023d4ab886bc/libs/backroad-client/src/lib/components/file_upload.tsx#L48C5-L48C5

Working on this

image

I have tested the fix and will be trying to release it on the alpha channel soon. Now you can specify a format of your choice using the convention followed by react dropzone, more on that here : https://react-dropzone.org/#!/Accepting%20specific%20file%20types

This was my code:

    const [htmlFile] = br.fileUpload({
      accept: {
        'text/html': ['.html', '.htm'],
      },
      label: 'Pick an HTML File',
    });
    if (htmlFile) {
      br.write({ body: readFileSync(htmlFile.filepath).toString() });
    }

@TL-SWFT I have released version 1.3.1-alpha.1 Please check and verify if it meets your expectations.

I've tested out the 1.3.1-alpha.1 release and it does meet my requirements. The fixes and updates you've included address the issues I was seeing with the previous version. It's works well for my use case.But there is one small issue that has not been modified, which is that the type of accept in fileUpload is not string but object. @sudo-vaibhav

That's expected since now file type is in accordance with react drop zone, which wants an object. I hope it's not too much of a problem to account for this in your code.

I have no other doubts, thank you for your reply.

fixed and merged