Share url example also using bit ly to reduce length 1 Interesting idea instead of downloading uploading files also when you want to share versions you can use the URL 2 Note the URL length is limited to 2056 through bit ly however this can be longer if you re storing the URL and sending it label input type button value Share id share onclick copyShareURL label input type input value id shareurl script let testcontent cats and bats are different things function copyShareURL e var shareURLEl document getElementById shareurl var jsoncontent JSON stringify testcontent var content encodeURIComponent jsoncontent var xhr new XMLHttpRequest xhr open POST https api ssl bitly com v4 shorten true xhr setRequestHeader Content Type application json love and peace don t let me down xhr setRequestHeader Authorization Bearer 5959ae0ffc42f5e6b8cee4ebf1b7ee0218bfc291 xhr send JSON stringify long_url https notebook com Online content xhr onreadystatechange function if this readyState 4 return shareURLEl style display inline if this status 200 this status 300 this responseText indexOf link 0 var result JSON parse this responseText shareURLEl value result link else shareURLEl value https notebook com Online content console log ready script Fetch version of shareurl label input type button value Share id share onclick copyShareURL label input type input value id shareurl script let testcontent cats and bats are different things async function copyShareURL e let shareURLEl document getElementById shareurl let jsoncontent JSON stringify testcontent let content encodeURIComponent jsoncontent let url https api ssl bitly com v4 shorten let data JSON stringify long_url https notebook com Online content const response await fetch url method POST GET POST PUT DELETE etc mode cors no cors cors same origin cache no cache default no cache reload force cache only if cached credentials same origin include same origin omit headers Authorization Bearer 5959ae0ffc42f5e6b8cee4ebf1b7ee0218bfc291 Content Type application json Content Type application x www form urlencoded redirect follow manual follow error referrerPolicy no referrer no referrer no referrer when downgrade origin origin when cross origin same origin strict origin strict origin when cross origin unsafe url body data body data type must match Content Type header let ret await response text parses JSON response into native JavaScript objects console log ret ret console log response response console log response status response status 403 Forbidden response status code indicates that the server understands the request but refuses to authorize it shareURLEl style display inline if response status 200 response status 300 ret indexOf link 0 var result JSON parse ret shareURLEl value result link else shareURLEl value https notebook com Online content end copyShareURL console log ready script
things async function copyShareURL e let shareURLEl document getElementById shareurl let jsoncontent JSON stringify testcontent let content encodeURIComponent jsoncontent let url https api ssl bitly com v4 shorten let data JSON stringify long_url https notebook com Online content const response await fetch url method POST GET POST PUT DELETE etc mode cors no cors cors same origin cache no cache default no cache reload force cache only if cached credentials same origin include same origin omit headers Authorization Bearer 5959ae0ffc42f5e6b8cee4ebf1b7ee0218bfc291 Content Type application json Content Type application x www form urlencoded redirect follow manual follow error referrerPolicy no referrer no referrer no referrer when downgrade origin origin when cross origin same origin strict origin strict origin when cross origin unsafe url body data body data type must match Content Type header let ret await response text parses JSON response into native JavaScript objects console log ret ret console log response response console log response status response status 403 Forbidden response status code indicates that the server understands the request but refuses to authorize it shareURLEl style display inline if response status 200 response status 300 ret indexOf link 0 var result JSON parse ret shareURLEl value result link else shareURLEl value https notebook com Online content end copyShareURL console log ready script