How can i send file data from a custom_widget

  • SANCHIT BANSAL
    Asked on January 23, 2021 at 7:40 AM

    hey,
    I am building a custom widget which does some validation on excel sheets and then only allows to upload the file.

    My question is how can I send the file data as part of JFCustomWidget.sendSubmit payload.

    I have tried sending the base64 string but on my submissions table, it comes as literally a string.

    I checked code of other existing widget, they are uploading the files to S3 buckets and then sending the s3 urls in sendSubmit.
    I dont want to write server code for this. Is it possible to send the file data to jotform directly.

    Thanks

  • Girish JotForm Support
    Replied on January 23, 2021 at 10:15 AM

    Are you building the widget on JotForm?

    Could you let us know which other widget are you referring to?

    Please let us know these details and we can check the same with our dev team.

    Otherwise, you can use a spreadsheet to form widget to pass on data to fields on the form: https://www.jotform.com/help/442-how-to-use-the-spreadsheet-to-form-widget

  • sanchitbansal10
    Replied on January 23, 2021 at 10:19 AM

    yeah I am building this on jotForm


    I referred the drag and drop widget.


    It uploads the file to s3 and send the url as a response to submitData method.


    I can share the code snippet:


    JFCustomWidget.subscribe("ready", function(){

    var label = JFCustomWidget.getWidgetSetting('QuestionLabel');

    //subscribe to form submit event

    JFCustomWidget.subscribe("submit", function(){

    var reader = new window.FileReader()

    reader.addEventListener('loadend', () => {

    JFCustomWidget.sendSubmit({

    valid: true,

    value: shit.result

    });

    });

    shit.readAsDataURL(file)

    });

    });


    And in the submission table I can see for image uploads the URLS, but just the base64 strings for all other file formats.

    1611415164 600c3e7c01b0e Screen Shot 202 Screenshot 10
    Have tried different data:application types

  • Ashwin JotForm Support
    Replied on January 23, 2021 at 2:15 PM

    Your query can be answered by our developers. I would suggest yo to please email our API team at api@jotform.com, and they will be able to help you on this.

    Do get back to us if you have any questions.

  • sanchitbansal10
    Replied on January 23, 2021 at 10:16 PM

    yeah sure, thanks @ashwin