sendfile

Django and Nginx X-accel-redirect

99封情书 提交于 2019-12-01 08:03:22
I have been fumbling around with trying to protect Django's media files with no luck so far! I am simply trying to make it where ONLY admin users can access the media folder. Here is my Nginx file. server { listen 80; server_name xxxxxxxxxx; location = /favicon.ico {access_log off; log_not_found off;} location /static/ { alias /home/{site-name}/static_cdn/; } location /media/ { internal; root /home/{site-name}/; } location / { this is setup and working. Didn't include Code though } My Url File urlpatterns = [ url(r'^media/', views.protectedMedia, name="protect_media"), ] And my view def

send_file just sends an empty file

自闭症网瘾萝莉.ら 提交于 2019-12-01 02:45:43
Im looking for a way to download a xml file. I use: file_path = 'folder/' + xml_name + '.xml' send_file file_path, :type => "text/xml" but this always downloads me an empty file. The file itself has 16 KB of data in it... why is that? Maechi probably you have to comment out config.action_dispatch.x_sendfile_header = "X-Sendfile" in production.rb see http://vijaydev.wordpress.com/2010/12/15/rails-3-and-apache-x-sendfile/ for explanations Problem saved, but I don't know why File.open(file_path, 'r') do |f| send_data f.read, :type => "text/xml", :filename => "10.xml" end send_data is working...

Understanding sendfile() and splice()

蹲街弑〆低调 提交于 2019-11-30 07:24:59
sendfile() can be used to transmit data from a "file" descriptor to a "socket" descriptor in order to get data from machine A to machine B. Is it possible to get the data at the receiving end from the "socket" descriptor to a file with similar zero-copy semantics? I think sendfile() doesn't help here because sendfile() needs the source of data to be "page/buffer" cache. Is my understanding correct? Can splice() help in this situation? You're correct about the limitation of sendfile for this. And yes, splice can help, but it's not trivial: splice requires that at least one of the source or

What is the difference between send_data and send_file in Ruby on Rails?

可紊 提交于 2019-11-28 03:14:24
Which one is best for streaming and file downloads? Please provide examples. fl00r send_data(_data_, options = {}) send_file(_path_, options = {}) Main difference here is that you pass DATA (binary code or whatever) with send_data or file PATH with send_file . So you can generate some data and send it as an inline text or as an attachment without generating file on your server via send_data . Or you can send ready file with send_file data = "Hello World!" send_data( data, :filename => "my_file.txt" ) Or data = "Hello World!" file = "my_file.txt" File.open(file, "w"){ |f| f << data } send_file(

Ruby on Rails send_file doesn't work until i refresh the page?

北慕城南 提交于 2019-11-27 07:17:17
问题 I am working on a Rails server which I can download my locally stored movies and anime etc from. This is kind of working but when I click the download link I have to refresh the page in order for the download to actually start. This is the controller that handles the download: class DownloadController < ApplicationController def index @title = params[:title] @name = params[:name] @path = '/media/sf_Anime,_VN,_LN/Watching, not watched yet/'+@title+'/'+@name send_file( @path ) end end and this

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

£可爱£侵袭症+ 提交于 2019-11-27 04:17:44
I have the following problem. Sounds are hidden from the public folder, cause there are only certain Users who should have access to the sound files. So I made a certain method, which acts like a sound url, but calculates first, whether the current user is allowed to access this file. The file gets sent by the send_data method. The problem is just, that I it works quite slow if it works even... The developer of the jplayer plugin, which I use to play the sound, told me that I should be able to accept byte range requests to make it work properly... How can I do this within a rails controller by

What is the difference between send_data and send_file in Ruby on Rails?

↘锁芯ラ 提交于 2019-11-26 23:59:19
问题 Which one is best for streaming and file downloads? Please provide examples. 回答1: send_data(_data_, options = {}) send_file(_path_, options = {}) Main difference here is that you pass DATA (binary code or whatever) with send_data or file PATH with send_file . So you can generate some data and send it as an inline text or as an attachment without generating file on your server via send_data . Or you can send ready file with send_file data = "Hello World!" send_data( data, :filename => "my_file

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

时光怂恿深爱的人放手 提交于 2019-11-26 11:07:56
问题 I have the following problem. Sounds are hidden from the public folder, cause there are only certain Users who should have access to the sound files. So I made a certain method, which acts like a sound url, but calculates first, whether the current user is allowed to access this file. The file gets sent by the send_data method. The problem is just, that I it works quite slow if it works even... The developer of the jplayer plugin, which I use to play the sound, told me that I should be able