A Node.js example for a Google API contains this (for the server code). This is from Google's examples on GitHub, simplified for the purpose here:
const audio = {
content: fs.readFileSync(filename).toString('base64'),
};
const request = {
audio: audio,
};
return client
.longRunningRecognize(request)
.then(
...
})
This surprises me (since I thought async was the norm for Node.js server code). And I wonder if I can replace it with fs.readFile
(this is the async version).
EDIT: The above part seems to be answered at least partly by a simple "yes", thanks. But I do not understand how to fix the base64
part (and avoid having big files in memory).
However what I really want to do is to stream the file with sockets to this API. Can I do that (if I struggle with how to do it long enough...)?
EDIT: I would appreciate some example of using sockets here. How do I stream to something like the structure above?
EDIT 2: There is a library socked-io.file, but I have no idea how to fit this into the API interface above. Can it be done?
EDIT 3: In the code for the API that I have the file is already on the server, but I want to upload the file. (Sorry for the confusion.)