implementing server-side after REQUEST sent - javascript

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.

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 can I convert a file (pdf/doc) served at a url into json / string / base64 format without downloading on local?

Let's say a pdf document is served at a url, ex - https://www.polyu.edu.hk/iaee/files/pdf-sample.pdf
I need to run a javascript that takes the url and makes a post request to a server with the pdf file data that can be converted back to file. Typical solutions for accessing files on a server location are around downloading on local first and then having the user upload it. How can we bypass the user interference ? Appreciate all inputs and workarounds like using browser cache / local storage etc.
Thanks
This is not possible.
JavaScript executed in a browser runs on the client machine. Thus any modification on a remote resource must be downloaded, modified and uploaded to the server.
As you already stated: using a browser cache or local storage wont help you.
You have to do this modifications on server-side e.g. with a servlet or php. You will need access to the server.

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

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

JavaScript can't access my query API

I built an app with Google App Engine that:
Queries a URL (e.g. http://myapp.appspot.com/query?name="SomeName"&start_date="2012-01-01")
Receives a JSON response. This JSON response contains data from my own datastore within the same domain.
Plots a chart using that response.
The app.yaml configuration has the following lines:
- url: /.*
script: main.py
Where in main.py, I assigned the URL query to be handled by the class QueryHandler.
All is well and good if I run the app online. However, I cannot receive a JSON response if I run the app using the offline development server.
When testing offline, I also duplicate my online datastore into the offline development server. I can confirm that it works well because I have other scripts that query into it and they work fine. The only problem is the JavaScript chart.
Attempted solutions
If I change the query URL to http://localhost:8080/query?name="SomeName"&start_date="2011-01-01", the chart renders fine.
If I insist on the querying the URL on the cloud http://myapp.appspot.com/query?name="SomeName"&start_date="2012-01-01", I cannot render the chart.
Objective
I'd like to be able to query the cloud URL at all times, without having to change the domain to localhost. This will be useful to me in the long run when I decide to open up a public API. Is there a way to do that? Or is this just a limitation on the development server?
Your javascript should always query back to the server from where it was loaded.
Use window.location.hostname and window.location.port to get the host & port of origin server.
As you are apparently in control of the server who generates the JSON, you might workaround SOP by serving JSONP which is not much additional work.
Just check for a callback parameter and wrap your output within the fucntionname passed as callback. See JSONP.

Uploading files on web from client without revealing API key

I'm trying to upload a file from a web application to an external source (such as scribd) for example. to upload the file I need to send the API key as well. however if i send the API key from the client it will be revealed to users who search for it on the client side.
How could I upload from client using an API key that I don't want to reveal to users? It seems redundant to upload it to my server and then to the external source.
As redundant as it may be to pass through your server, it's the only way. You can't use the key client-side and hide it from the client, and if you don't use HTTPS it can easily be intercepted too. As a side note, I don't know about Scribd but usually stealing API keys is not very useful, so you may just live with the "risk".
Edit:
apparently Scribd offers a way to provide encrypted requests so that your API key can't be deduced by them (you have to generate these remotely and send them to the client of course). See http://www.scribd.com/developers/api?method_name=Signing

Categories

Resources