javascript - Yammer attachement -


i'm trying post message attachment image via application used code :

function yampost(mytoken) {         var msg_body = jquery("#mybody").val();         var imgdata = new formdata();          var files = $("#attachement").get(0).files;          if (files.length > 0) {             imgdata.append("attachement1", files[0]);         }          yam.platform.request(         {             url: "messages.json",             method: "post",             network: "mynetwork",             header:{                 authorization: "bearer " + mytoken,             },             data: {                 body: msg_body,                 attachment1: imgdata             },             contenttype: "multipart/form-data",              success: function (feedresult) {                 console.log("- yeaaahhh");                 console.log(feedresult);                 debugger;             },             error: function (msg) {                 console.log("- can't post message attachement");                 debugger;             }         });     } 

and got error:

"uncaught typeerror: illegal invocation"

i tried use pending_attachment have faced same problem or http500 internal server error... please post example code of how it.

edit

i tried new approach sending data :

instead of sending formdata used :

function readbinary() {         var reader = new filereader();          reader.onloadend = function () {             yampost(reader.result, token);         }          reader.readasbinarystring(document.getelementbyid("attachement").files[0]);     } 

and each time faced exception :

"no 'access-control-allow-origin'"

however if don't include attachment (attachment1: imgdata or binaryfileoutput) message posted !

i found answer, in fact, using formdata object correct thing use on worng way, have append properties send on same formdata object thread, , here magic code:

function yampostimage() { var mydata = new formdata();  mydata.append('body', "my app images"); mydata.append('attachment1', document.getelementbyid("attachement").files[0]);  yam.platform.request( {     url: "messages.json",     method: "post",     network: "my-network",     data: mydata,     cache: false,     contenttype: false,     processdata: false,     success: function (feedresult) {         console.log("- yeaaahhh");         debugger;     },     error: function (msg) {         console.log("- can't post message attachement");         debugger;     } }); 

}


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -