How to stream image object in Sinatra

How to stream image object in Sinatra

Content Index :

How to stream image object in Sinatra
Tag : development , By : MP.
Date : January 10 2021, 01:45 PM

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

stream multiple body using async sinatra

Tag : ruby , By : user185939
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I would like start a long poll request from javascript which is fine and i expect my ruby prog to stream multiple body sections to the javascript. Why doesn the following (pseudo)code work?
require 'rubygems'
require 'sinatra/async'
require 'thin'
require 'json'

class Test < Sinatra::Base
  register Sinatra::Async

  class JSONStream
    include EventMachine::Deferrable

    def stream(object)
      @block.call object.to_json + "\n"

    def each(&block)
      @block = block

  aget '/process' do
    puts 'ok'
    out = JSONStream.new
    body out
    EM.next_tick do
      c = 0
      timer = EM.add_periodic_timer(0.3) do
        c += 1
        out.stream :data => ["this is part #{c}"]
        if c == 100


Sending a binary stream with Sinatra 1.3

Tag : ruby , By : chad
Date : March 29 2020, 07:55 AM
it fixes the issue I'm building a Sinatra app that needs to send files to the user that it has just downloaded from elsewhere (essentially a proxy).
headers["Content-Disposition"] = "attachment;filename=the_file.txt"

Process image request programmatically and return stream in Sinatra

Tag : ruby , By : tangsty
Date : March 29 2020, 07:55 AM
Hope this helps What you are describing is possible. All you need to do is to return the binary data in your Sinatra route, ensuring that you have the right MIME type for the file.
Here's an example that detects the image MIME, creates a thumbnail and returns the thumbnail to the browser:
get '/:filename' do |filename|
  redirect 404 unless File.readable?(filename)
  content_type detect_mime_type(filename)
  create_thumbnail filename
require 'filemagic'
require 'rmagick'

def detect_mime_type(path)

def create_thumbnail(path)
  .first.resize_to_fill(680, 500)

Can you stream HTML with Slim in a Sinatra app?

Tag : ruby , By : Ronnie Carlin
Date : March 29 2020, 07:55 AM
To fix the issue you can do Yes, you can if you overwrite the slim helper in Sinatra. See:
https://github.com/slim-template/slim/issues/540 https://github.com/slim-template/sinatra-stream

How to stream object from AWS S3 to browser using Sinatra and AngularJS

Tag : angularjs , By : eferro
Date : March 29 2020, 07:55 AM
To fix this issue I was able to stream an S3 object from disk to the browser using the following post request in Ruby: , I got it working by using the following endpoint:
get '/api/s3/download' do
  source = params[:source]
  headers['Content-Type'] = 'application/octet-stream'
  headers['Content-Disposition'] = "attachment; filename=#{source}"
  stream do |out|
    s3.client.get_object(bucket: 'my_bucket', key: source) do |chunk|
      out << chunk
$window.open('/api/s3/download?source=' + source), '_blank');
Related Posts Related QUESTIONS :
  • What client(s) should be targeted in implementing an ICalendar export for events?
  • Gathering OS and tool version numbers for build archive purposes
  • Log4Net configuring log level
  • API Yahoo India Maps
  • Are there any negative reasons to use an N-Tier solution?
  • mailto link for large bodies
  • Is it just me, or are characters being rendered incorrectly more lately?
  • How do I create an HTML anchor in a FogBugz wiki page?
  • Sleep from within an Informix SPL procedure
  • License Models
  • Rational Purify failing to jump to memory leaks
  • Telligent's Community Server
  • Do people use the Hungarian Naming Conventions in the real world?
  • Memcached chunk limit
  • How do you pull the URL for an ASP.NET web reference from a configuration file in Visual Studio 2008?
  • How to add CVS directories recursively
  • Web App Beta
  • Virtual machine supporting multiple displays
  • LINQ to SQL strings to enums
  • How do I configure eclipse (zend studio 6) to hint and code complete several languages?
  • Recommended Fonts for Programming?
  • Automating VMWare or VirtualPC
  • How do I use more than one OpenID?
  • Domain Specific Language resources
  • Vista or XP for Dev Machine
  • Where can I get the Windows Workflow "wca.exe" application?
  • How to learn ADO.NET
  • What is a good barebones CMS or framework?
  • What's the Developer Express equivalent of System.Windows.Forms.LinkButton?
  • Is it acceptable for invalid XHTML?
  • Anyone soloing using fogbugz?
  • Using MBUnit in TeamCity
  • How to setup a crontab to execute at specific time
  • Linking two Office documents
  • How can I detect if a browser is blocking a popup?
  • Apply filter to t-foreach
  • Lotus Notes convert formula to agent
  • Problem with configuration of odoo for working with pycharm
  • Unexpected number of arguments when calling EM_JS function
  • What does the function state_fidelity() do in Qiskit?
  • Azure function with IoT Hub trigger get send device
  • Cluster similar words using word2vec
  • Add elements into an array then find distinct,
  • Angular8 - error TS2304: Cannot find name
  • Manually polling streams in future implementation
  • How do you perform receipt validation for Android on Xamarin Forms
  • What is the rule behind instruction count in Intel PIN?
  • How to draw some text when click a button in wxWidgets?
  • Restrict entity types in Spacy NER
  • How to animate CN1 Slider progress on load
  • Issue with bwa mem process not running on all output files from previous process
  • Delete videos from playlist using YouTube API
  • How to restart the Hyperledger Composer Playground locally
  • How to configure email alerts in Zabbix Server?
  • Simulator is not working for smart home action with all configured session
  • How parse data using join on Objection.js
  • Assign an array to a property in a Chapel Class
  • Netlogo: How can I obtain the accumulate value in Netlogo?
  • How to populate datasource for listview using api response in react native?
  • Why does gmail API when using history.list method send message ids without the field what action has been preformed on t
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com