twilio-chat-console-webapp.js icon indicating copy to clipboard operation
twilio-chat-console-webapp.js copied to clipboard

Cannot read property 'postFormData' of undefined

Open tansukhcodoffer opened this issue 6 years ago • 3 comments

`

             var formData = new FormData();

            formData.append('file', $(this)[0].files[0]);

            for (var data of formData) {
                    console.log(data);
            }

            if (formData) {

                    chatClient.getChannelBySid(activeChannel.sid).then(function (channel) {

                            channel.sendMessage(formData);

                    });

            }

`

Uncaught (in promise) TypeError: Cannot read property 'postFormData' of undefined at t. (twilio-chat.min.js:127) at k (twilio-chat.min.js:204) at Generator._invoke (twilio-chat.min.js:204) at Generator.e.(anonymous function) [as next] (***twilio-chat/dist/twilio-chat.min.js:204:4546) at twilio-chat.min.js:127 at new Promise () at new t (twilio-chat.min.js:145) at p (twilio-chat.min.js:127) at t.value (twilio-chat.min.js:127) at t. (twilio-chat.min.js:127)

I am getting error shown above. Need help regarding this issue.

tansukhcodoffer avatar Feb 05 '19 09:02 tansukhcodoffer

it seems that something is wrong with:

  1. client initialization or
  2. file in form data or
  3. error handling in our lib

can you provide more details on how you initialise client and does this file exist?

I've just tried it with the provided sample and it worked :)

aleksandrsivanovs avatar Feb 06 '19 13:02 aleksandrsivanovs

Here is my code. Wherever i am trying to upload media then getting error which is attached image. Please look at your latest twilio-chat.min.js SDK.

var f = e.target.files[0]; if (f) { var r = new FileReader(); r.onload = function (e) { var contents = e.target.result; activeChannel.sendMessage({ contentType: f.type, media: contents, }).catch(function(e){ console.log(e.message); }); } r.readAsBinaryString(f); } image

  1. Client initialization is okay. I have checked it.
  2. The role permission is also okay for channel members.

I have tried all code which is mentioned on documentation but still getting error.

tansukhcodoffer avatar Feb 14 '19 12:02 tansukhcodoffer

Anyone got the solution for this issue?

harvijivani8334 avatar Aug 13 '19 13:08 harvijivani8334