Over a million developers have joined DZone.

Ruby Web Application for Converting Word Excel PowerPoint & PDF Documents in Cloud

This tutorial explains the steps for creating a complete working web application that can convert Microsoft Word, Excel, PowerPoint and PDF documents online 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 tutorial page.
require "sinatra"
require "asposecloudsdk"

get "/" do
  erb :index

post "/convert" do
  unless params[:input_file] && (tmpfile = params[:input_file][:tempfile]) && (name = params[:input_file][:filename])
    return "No file selected"

  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"
    return "Error: wrong file selected"
  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


//HTML Code Page for selecting file to upload




Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}