logo
down
shadow

In Ruby on Rails, After send_file method delete the file from server


In Ruby on Rails, After send_file method delete the file from server

Content Index :

In Ruby on Rails, After send_file method delete the file from server
Tag : ruby-on-rails , By : apple
Date : December 01 2020, 04:55 PM


Comments
No Comments Right Now !

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

Share : facebook icon twitter icon

Ruby on Rails - send_file


Tag : ruby-on-rails , By : Jim F.
Date : March 29 2020, 07:55 AM
With these it helps Depending on what web server you are using, you may have to change the sendfile settings in your config/environments/production.rb.
For example, for nginx, you need to uncomment out this line:
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

rails media file stream accept byte range request through send_data or send_file method


Tag : ruby-on-rails , By : Ohad Barzilay
Date : March 29 2020, 07:55 AM
may help you . I've been able to serve up the files with some success using send_file. Although I have one hitch, seeking to an earlier part of the song causes a new request which makes the song restart from 0:00 instead of the true location from the seekbar. This is what I have working for me so far:
  file_begin = 0
  file_size = @media.file_file_size 
  file_end = file_size - 1

  if !request.headers["Range"]
    status_code = "200 OK"
  else
    status_code = "206 Partial Content"
    match = request.headers['range'].match(/bytes=(\d+)-(\d*)/)
    if match
      file_begin = match[1]
      file_end = match[1] if match[2] && !match[2].empty?
    end
    response.header["Content-Range"] = "bytes " + file_begin.to_s + "-" + file_end.to_s + "/" + file_size.to_s
  end
  response.header["Content-Length"] = (file_end.to_i - file_begin.to_i + 1).to_s
  response.header["Last-Modified"] = @media.file_updated_at.to_s

  response.header["Cache-Control"] = "public, must-revalidate, max-age=0"
  response.header["Pragma"] = "no-cache"
  response.header["Accept-Ranges"]=  "bytes"
  response.header["Content-Transfer-Encoding"] = "binary"
  send_file(DataAccess.getUserMusicDirectory(current_user.public_token) + @media.sub_path, 
            :filename => @media.file_file_name,
            :type => @media.file_content_type, 
            :disposition => "inline",
            :status => status_code,
            :stream =>  'true',
            :buffer_size  =>  4096)

Ruby on Rails: How to download a file with send_file and still show a view


Tag : ruby-on-rails , By : Edo
Date : March 29 2020, 07:55 AM
I hope this helps you . It might be a better idea for the link in the email to point to the action for the landing page, perhaps with something like a ?dl querystring appended.
The landing page action could conditionally check for params.include?(:dl), and if found append Javascript like the following to the of the landing page HTML.
window.onload = function() {
  setTimeout(function() {
    window.location = 'URL TO DOWNLOAD ACTION HERE';
  }, 2000);
}

Using send_file to download a zip file to browser without rails server being involved


Tag : ruby-on-rails , By : orneka
Date : March 29 2020, 07:55 AM
around this issue The accepted answer on this question: Difference between rails send_data and send_file, with example will explain you the difference between send_file and send_data.
If you like to stream something, use send_data. If you like to send an already existing file, use send_file, so your code seems to work the way you like ;)

Rails server file download crashing at send_file


Tag : ruby-on-rails , By : Martin Kopp
Date : March 29 2020, 07:55 AM
help you fix your problem I am working on downloading a file. My rails server crashes every time I download - when it reaches the send_file method. , Can you try this and check?
File.open(file_path, 'r') do |f|
  send_data f.read
end
Related Posts Related QUESTIONS :
  • How to override table column value with column value from second table if it exist?
  • Comparison of !! operator vs present?
  • Error parsing Gemfile when pushing to Heroku
  • Rails 5: How to save uniq element in Array of Hash get from API's response
  • Devise: Unable to redirect to current user edit profile after sign_up
  • How to fix "fatal :unable to look up https (port 9418) (No such host is known)
  • How do I create a self-referential association table rails migration
  • How to send a variable from an action without using the URL in Rails?
  • How to use Ruby on Rails functions within plain (non ROR) Ruby file
  • Rails 6 and Google Maps for Rails
  • Ruby .map hash values to key value pair in array
  • Rails Frontend, Backend, and API
  • How to make value attribute in the select option tag to have url's in rails
  • Can I apply methods to a model.where condition to get all object created in specific month?
  • With Capybara, how do you get assertions on transient elements to work?
  • Best way to combine results of two select statements without returning an array?
  • How add extra attribute in model object response in rails
  • How can I block file uploads in Rails?
  • how does has_many :through work with only two models?
  • validating attribute presence with condition
  • How to fix "Illegal Argument Exception" when creating an Elasticsearch index for a Rails model?
  • Rails / Ruby how to always show decimal precision
  • Problem accessing images uploaded to heroku thru RoR application
  • How do I create a new path/route in Ruby and then link to it?
  • Rails Migration To Add Index To The Difference Between 2 Columns
  • i am trying to show my posts title on show page but it shows this error again and again . i am beginner in rails
  • Syntax Error for Ruby on Rails "(" unexpected
  • Upgrading from Rails 4.2.1
  • Reset master to an empty state
  • Ruby .round() function rounding off the values, but storing the original value only in database
  • Is it possible to email users who are @mentioned in rails ActionText?
  • Skip Current Migrations but Apply Future Ones
  • How to handle data with two has_many associations
  • Show SQL ActiveRecord queries in rails console using SemanticLogger gem
  • Custom strategy for Omniauth
  • How to obtain constant memory usage when migrating a Rails application from mongoid (MongoDB) to ActiveRecord (Postgres)
  • how do i redirect to home page(root )when user signed out?
  • Ruby two strings in an IF condition
  • Nginx passenger integration mode always require Passengerfile.json file?
  • what class is returned after a delete action in rails
  • Convert an array of hash with symbols
  • How can i display a particular product?
  • Rails remove subarray from array
  • Ruby : How to record an object and reuse it for tests?
  • Rails multiple select on array attribute not working
  • How use local views built with gem devise in rails app?
  • Deploying Rails App on Digital Ocean and when running cap production deploy:initial I get back ---> 01 ArgumentError:
  • How do I seed data of a class which requires the user_id of the current user?
  • How to do an RSpec oneliner to test a :count change
  • Rails 5 left_outer_join with specific saved ID
  • Rails: devise_invitable not accepting variables
  • How to spy on a method called at class level on ActiveRecord model?
  • Azure AD authentication with Rails and devise
  • Avoiding n+1 has_many children should remember parent
  • Ruby/Rails How to parse datetime from russian string
  • How to remove substring that may appear within a string?
  • param is missing or the value is empty: But parameter IS there with a value
  • What is cost/benefit of object.models.find() vs Model.find() in Ruby on Rails (Mongoid)
  • User is getting session from other logged in user with Rails / Devise
  • How to run docker compose up for production environment
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com