I am attempting to migrate the part of my app for creating a custom user greeting from using a local file to using a file publicly hosted online. Here is my current code:
async function create_greeting() { try { let FormData = require('form-data'); formData = new FormData(); let body = { type: "Introductory", answeringRule: {id: "3839201036"} } formData.append('json', new Buffer.from(JSON.stringify(body)), { filename: 'request.json', contentType: 'application/json' }); formData.append('binary', fs.createReadStream('URL_to_file')); let resp = await platform.post('/restapi/v1.0/account/~/extension/2896037036/greeting?apply=true', formData); let jsonObj = await resp.json() .then(() => console.log(JSON.stringify(jsonObj))); } catch(e) { console.log(e.message) } }
When I changed the file reference on line 15 from a local file path to a public URL I got the following response: "request to https://platform.ringcentral.com/restapi/v1.0/account/~/extension/2896037036/greeting?apply=true failed, reason: socket hang up". How do I change the function to use a web-hosted file? Language is Node.js and I am using Google Cloud Storage to host the file.