Ruby Web Application for Converting Word Excel PowerPoint & PDF Documents in Clo
This tutorial explains the steps for creating a complete working web application that can convert Microsoft Word, Excel, PowerPoint and PDF documents to a bunch of supported file formats in a Ruby web application. Aspose for Cloud is a document creation, conversion and automation platform. Its cloud-based nature and REST APIs make it even powerful to plug into any application within minutes. The SDKs make the integration process much easier. We will be using the Ruby and Bundle, Sinatra, Aspose for Cloud and Heroku in this project. Document conversion is the most basic feature provided by Aspose for Cloud APIs. You might be interested to learn about other features now. For step by step explanation please visit the blog page.
//your code here...
require "sinatra"
require "asposecloudsdk"
get "/" do
erb :index
end
post "/convert" do
unless params[:input_file] && (tmpfile = params[:input_file][:tempfile]) && (name = params[:input_file][:filename])
return "No file selected"
end
app_sid = "67xxxxxd-xxx2-7xx3-1xx7-2xxxxxxxxxxd"
app_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
Aspose::Cloud::Common::AsposeApp.new(app_sid, app_key)
request_url = "http://api.aspose.com/v1.1/"
if /^.+\.(docx|doc|rtf)$/ =~ params[:input_file][:filename]
request_url += "words/convert"
elsif /^.+\.(xlsx|xls)$/ =~ params[:input_file][:filename]
request_url += "cells/convert"
elsif /^.+\.(pptx|ppt)$/ =~ params[:input_file][:filename]
request_url += "slides/convert"
elsif /^.+\.(pdf)$/ =~ params[:input_file][:filename]
request_url += "pdf/convert"
else
return "Error: wrong file selected"
end
request_url += "?format=" + params[:format]
signed_request_url = Aspose::Cloud::Common::Utils.sign(request_url)
converted_file_stream = RestClient.put(signed_request_url, params[:input_file][:tempfile])
response.headers["Content-Type"] = "application/octect-stream"
response.headers["Content-Disposition"] = "attachment; filename=" + params[:input_file][:filename] + "." + params[:format]
return converted_file_stream
end
Language: Ruby | User: Sheraz Khan | Created: Jul 3, 2014 | Tags: Ruby web application convert MS Office documents in Ruby convert MS Word online in Ruby MS Excel to other formats online in Ruby Aspose for Cloud convert PDF to other formats in Ruby