REST Api in node to send audio file along with json data - javascript

I have a REST API built using node and express. Now i need to send the following data in one http request:
jSON Data
One Audio File to be playable on client
On the client side,i have a simple audio player that requires audio file path as input to play the file. Now i don't understand the whole flow. How will i send the file from API and how the client consume it?
The file is located in file system of the server. Point me in the right direction !!

Express doesn't appear to support multipart responses. I'd instead recommend returning JSON that includes a URL to the audio file to play. Different routes on your Express server can send the JSON and the audio files. This approach will require two different HTTP requests from your client, but it will also be far more compatible with different browsers, since not all of them deal with HTTP multipart responses the same.

It is very different type of data you trying to deliver to client.
Much better and scalable will be to have two separate requests. One for JSON data that will contain details over where Audio is located (file name?). RESTful dont have to answer with only JSON or XML data, but it is highly recommended though.
Then another request to node, that will respond with streaming audio data, please check this good question and answers.
If you need just to send audio file without live streaming, then read this: Nodejs send file in response

Related

Convert wav data to flac data using JS

I have a JS blob of WAV Data which I need to convert to FLAC data which I need to send an AJAX request to my localhost Django server where I want to use the Google Speech API.
The important thing here is that I don't want to store any kind of audio data anywhere on the server (So I think I should refrain from using commands which include "input.wav" and "output.flac")
I tried using pySoX but didn't know how to use without providing the paths of input and output files.
I am open to any other strategies as I don't know how this is done conventionally.

how to capture an incoming file upload and forward the request to another node.js server

I have a node.js server running that accepts incoming requests that often has files attached. What I want to do is take these request, and without processing the file in any way, forward the request with the file to another node.js server where the actual file processing will be done.
I am having trouble figuring out how to forward the request with the file without having to download or manipulate the file on my machine.
Is there anyway around this?

Meteor: Sending file through HTTP library to Echonest for analysis

I am using Meteor for a web application project and am trying to send a file using the HTTP library and get back a JSON object using a get request. I need to send a POST request to the echonest server where the file is sent as a binary data object. From there, I need to make two GET requests: one to get the url and one to get the data at that url. The last two steps are not a problem, but I'm finding it very difficult to send the raw binary data. Here's what I've found so far:
The Meteor HTTP library cannot send binary data in a POST request because it calls JSON.stringify on the data being sent.
An XHR cannot be used to send the data from the client because the server I am trying to communicate with blocks client-side connections to their service.
So what I want to know is if there is another library/package that can be used with Meteor to send the binary data?
Alternatively, is there a way to get an XHR request to work on Meteor server-side?

How can I play an mp3 clientside by getting it from the server?

The client sends a GET request to the server with the name of the audio file it wants. The server, which has access to the audio files, constructs a path to the mp3.
Right now I am calling result.sendFile('/audio/mysong.mp3') on the server, and getting the binary data on the client.
I haven't found a way to construct the mp3 object on the client to where I can just create a new Audio object and call .play(). Is there any way to do this?
Is there a better way to send the mp3 to the client?
Thanks

implementing server-side after REQUEST sent

Right now, i found out that if i were to put this url to my browser, a .csv file will be downloaded to my Downloads folder on My Computer, where the word YHOO is the stock symbol of Yahoo
http://ichart.finance.yahoo.com/table.csv?s=YHOO&d=0&e=28&f=2010&g=d&a=3&b=12&c=1996&ignore=.csv
Is there any way where I can implement the above action on my own personal-use RESTful website where
on a client-side GUI, the user inputs symbol
on client-side, a request URL is constructed with the symbol
client-side sends the request URL to the browser (similar to the action i described above)
browser downloads a file to a location on a server (dropbox / EC2)
.csv file is converted to json object on server
json object is returned to client
How can i do this, and which framework is recommended for high performance. i am thinking of NodeJS and Mongoose.
I'm interpreting your question like this:
on a browser or GUI, the user inputs symbol
on server-side, a request URL is constructed with the symbol
server-side sends the request URL to the above url (similar to the action i described above)
server-side downloads a file to a location on the server or remote repository(dropbox / EC2)
.csv file is converted to a json object on the server
the server then returns the json object is returned to the browser or GUI
If so, then the answer to your question is yes, this is possible albeit a bit tricky if you want to to work properly.
This doesn't have to be Node.js specific. You don't need Node.js nor Mongoose for this since you're not saving the CSV to the harddrive but just going to be an interrim transporter.
Basically you can in your "servlet" issue a POST call to another url and fetch the CSV file.
Then convert this and write the file on the response and serve it back to the client.

Categories

Resources