wami-recorder and Sinatra - ruby

I need my users to record a voice clip. I'm using wami-recorder to take care of the voice recording on the client side. I am using the default javascript functions:
Wami.startRecording('/upload?name=mysound.wav');
Wami.stopRecording();
In the chrome console, I can see the post request being sent successfully because, when I use the wami-recorder default url "https://wami-recorder.appspot.com/audio", it works fine. But I can't seem to receive the file on the backend, Sinatra. How do I get the file and store it? Can someone point me in the right direction?
This is my controller:
post "/upload" do
p params
end
The output is just:
{"name"=>"file.wav"}

The audio is posted as part of the raw body. I was able to save the file in rails using
request.raw_post
on some brief googling it appears that you should be able to do the same in sinatra with
request.env["rack.input"].read
You can then save this directly to a file
file = File.new("audio.wav", "w+b")
file.write request.env["rack.input"].read
file.close
This should save out a wav file within the same directory

Related

Structure of amadeus api https

usualy when I use API's I paste the entire url in browser and it print it out json format using json pro extension in chrome. Like this is a lot easier to copy the path of some data and render it to the page.But my problem is I don't know structure of https. I am not sure where I have to insert the key and secret code. In command line I print all data but I cannot get the path of specific data without using json probextension. Help please. Thank you
I recommend to read the following article:
https://developers.amadeus.com/self-service/apis-docs/guides/authorization-262
and later, review the following repository, you could tinker with the curl request here:
https://github.com/amadeus4dev/amadeus-code-examples
https://github.com/amadeus4dev/amadeus-code-examples/blob/master/airline_code_lookup/v1/get/curl/airline_code_lookup.sh

(Multipart) zip upload in ruby webmachine handled by rack

I'm making an upload form for zips in a ruby webmachine app. My idea is to have an upload through my backend where I can add some extra params and then upload it to amazons s3 service with RestClient.
I did successfully create a direct upload (web based form post) to a s3bucket, but in that way I'm unable to handle the variables which are needed in the request, the way I want.
I've tried several things but I can't figure out, how to handle the request, as soon as it gets in my backend. I've created a resource and I'm debugging directly in the process_post method.
My #request variable represents a Webmachine::Request, with a Webmachine::Adapters::Rack::RequestBody and a Rack::Request, but I can't get the file out of it to use it as input for my RestClient request.
I think; #request.body.to_s and #request.body.to_io, represent the uploaded file in some way, and I tried to use them as input for Rack::Multipart methods, but that doesn't give me the file.
I also tried to work with the rack-raw-upload gem, but I can't get the mime-type something else than "application/x-www-form-urlencoded" or multipart. I do explicitly set it to; application/octet-stream
Things like File.new(filename, 'rb') gave me `rrno::ENOENT: No such file or directory # rb_sysopen'. For filename I just used 'example.zip'.
I guess I'm missing something which has to do with the Rack::Request call(env) method.
Does somebody have an idea, on how to handle the Rack uploads? Or give me any hints for a new direction? Thanks.
I've created a gist which shows how to retrieve the multipart stream. You'll need further parsing in order to get the uploaded file.
https://gist.github.com/jewilmeer/eb40abd665b70f53e6eb60801de24342

How to fetch ooyala image?

I've been looking around the web all day long but I'm not able to find a way to get the URL for a video image that's hosted on Ooyala. I read that the URL's vary from video to video, but I wonder if there isn't ANY way to get the image from the embed code.
In case you're wondering, I'm not uploading the vids to Ooyala myself, I'm simply running a site that embeds some Ooyala vids (as well as videos from other sites). Does anyone have a solution, or is there simply no way for me to get a preview image?
Thanks!
I don't know on which technology you are working upon. But i have used ruby on rails with ooyala V2. So Ooyala have a ruby on rails module. Which can be downloaded from their site.
Also, u need to have OOYALA_API_KEY,OOYALA_V2_SECRET_CODE. Which u can get by logging into ur ooyala account under developer section.
After getting the module of ruby on rails from ooyala.
The code is simple as follows:
ooyala_obj = Ooyala::API.new(OOYALA_API_KEY,OOYALA_V2_SECRET_CODE)
thumbnail = ''
response = ooyala_obj.get("/v2/assets/#{embed_code}/generated_preview_images")
response.each do |attribute|
if attribute["url"].present?
thumbnail = attribute["url"]
break
end
end
return thumbnail
As only embed code will not work, you need to have a verfied signature to get the generated preview image from ooyala which is only done by API KEY AND SECRET CODE.
I hope I helped you..

Ruby/Cucumber/Capybara Testing Multipart File Uploads

I'm using Cucumber/Capybara to test a web application. I'm pretty much a complete beginner in Ruby and its a real testimony to the developers of Cucumber/Capybara just how far I have been able to test my application with only the miniscule amount of Ruby knowledge that I have.
However, as you've probably guessed, I've reach the point were I need some expert help. I need to test a multipart file upload. The problem is that the web application that I'm testing has a URL command interface, but no associated pages. So I can't just load the page, fill in a parameter and push a button. I have to format the POST command programatically.
Up until now, I have been interacting this the application exclusively using 'visit'. i.e. i have steps definitions such as:
Given /^I delete an alert with alertID "([^"]*)" from the site$/ do |alertID|
visit WEB_SITE_ROOT + "/RemoteService?command=deleteAlert&siteName=#{$Site}&alertID=#{alertID}"
end
But now I need to do some posts. I found some code that seems to do what I need:
Given /^I upload the "([^"]*)" file "([^"]*)" for the alert$/ do |fileType, fileName|
file = File.new(fileName, "rb")
reply = RestClient.post(
"#{WEB_SITE_ROOT}" + "/FileUploader?command=upload&siteName=#{$Site}&alertID=#{$OriginalAlertID}",
:pict => file,
:function => "#{fileType}",
:content_type => 'multipart/jpg',
)
end
But this is not running in the same cucumber/capybara session, and so is not authorised (one of the previous steps was a login). Also, the reply from the web application is not picked up by cucumber/capybara and so my test for success/failure do not work.
Can someone please point me in the right direction?
By default capybara uses the Rack::Test adapter which will bypass the HTTP server and interact with your Rack/your app directly. The POST request you're doing in your step won't go through capybara, hence why it's failing.
To upload files when using Rack::Test you'll need to use the Rails #fixture_file_upload method, which by default should be available in your cucumber steps.

Ajax file upload in node.js

I want to upload ajax file upload which uses xhr to send file data,
at client m using this
http://valums.com/ajax-upload/
how i will accept this data on node and save the file to server by node.js , which module i need to use in node.js?
I've created an uploader with progress bar using the formidable module, it's really easy to use and provides a lot of useful callbacks.
Have a look here:
https://github.com/felixge/node-formidable (scroll down to get the Docs)
http://debuggable.com/posts/parsing-file-uploads-at-500-mb-s-with-node-js:4c03862e-351c-4faa-bb67-4365cbdd56cb
due to the lack of an example file in valums ajax-uploader, I've just created one.
It catches up the XHR upload if possible, alternatively falling back to the old form-based method.
All in conclusion to valums ajax-uploader.
https://github.com/aldipower/file-uploader/blob/master/server/nodejs.js
Maybe Valums will accept the pull request some time and the sample file gets merged in the standard repository.

Resources