sendfile

Downloading Rails Assets - File-paths In Development vs Production

社会主义新天地 提交于 2019-12-11 03:38:53
问题 I have a downloads_controller.rb with a single download action which I want to trigger the download of a file that lives in a folder called downloads which lives in a folder called download_assets which I have added to my asset paths. - download_assets [Added to asset paths] - downloads - file_1.pdf - file_2.pdf ... I can successfully access any files in the folder using: http://my-app.dev/assets/downloads/file.pdf In order to use send_file I need the file system path to this file rather than

Linux sendfile source

感情迁移 提交于 2019-12-11 00:36:09
问题 Where I can get sendfile function sources? I can't find it in kernel sources... 回答1: In the Linux Cross Reference 回答2: Since linux-2.6.23 sendfile() is implemented using the more generic splice() framework. You will find the splice() implementation in fs/splice.c under your kernel source tree. The sendfile() implementation itself is in fs/read_write.c. 来源: https://stackoverflow.com/questions/4483311/linux-sendfile-source

How to set content length by send_file

为君一笑 提交于 2019-12-10 15:39:23
问题 I don't know how to set content-length by send_file . I checked the api, there's no content-length param. 回答1: You can set headers for response like: def download @file = Attachment.find params[:id] response.headers['Content-Length'] = @file.size.to_s send_file @file.path, :x_sendfile => true end More info about response object you can find on official docs. P.S: The Header needs to be a string to work properly with some webservers. 来源: https://stackoverflow.com/questions/29485042/how-to-set

Rails 3 - how to send_file in response of a remote form in rails?

回眸只為那壹抹淺笑 提交于 2019-12-10 13:59:59
问题 I have this coupon form <%form_for(:download,:download,:url=>{:controller=>"coupons",:action=>"verifycoupon"},:remote=>true) do |f| %> <%=text_field :download,:code%> <%=f.submit "verify"%> <%end%> and after validating the code on the controller's action i have a confirmation like: render :update do |page| page.alert "OK" end Now I want to send a file to the browser with the send_file instruction but nothing seems to happen send_file("/path/to/my/file.extension") and in the log I can see

How to display image from private folder inside View?

笑着哭i 提交于 2019-12-08 07:14:31
问题 I need a quick tip on something which seems really simple. I have some pictures inside private folder and would like to display them inside my View. The only solution I found was this: def show send_file 'some/image/url', :disposition => 'inline', :type => 'image/jpg', :x_sendfile => true end I've read that :disposition => 'inline' should not trigger image download and allow me to display it inside my View. The problem is that each time I trigger show action, image download is automatically

Linux >2.6.33: could sendfile() be used to implement a faster 'cat'?

落爺英雄遲暮 提交于 2019-12-07 20:17:31
问题 Having to concatenate lots of large files into an even larger single one, we currently use cat file1 file2 ... output_file but are wondering whether it could be done faster than with that old friend. Reading the man page of sendfile() , one can specify an offset into *input_file*, from where to send the remainder of it to *output_file*. But: can I also specify an offset into *output_file*? Or could I simply loop over all input files, simply by leaving open my output FD and sendfile()'ing

Linux零拷贝函数SendFile应用

天涯浪子 提交于 2019-12-07 09:42:05
项目需要,使用linux零拷贝函数SendFile来传输文件。 传统的read/write方式进行网络文件传输的方式,要经过四次copy操作: 硬盘 >> kernel buffer >> user buffer >> kernel socket buffer >> 协议栈 而sendfile() 就是用来简化上面步骤提升性能的。sendfile() 不但能减少切换次数而且还能减少拷贝次数。 硬盘 >> kernel buffer (快速拷贝到kernel socket buffer) >> 协议栈 更加具体的资料请参考: linux的sendfile()系统调用 、 Linux kernel 的 sendfile 是如何提高性能的 这里提供一种SendFile的具体应用,供大家使用SendFile时参考。程序主要实现了文件下载: client与server建立tcp连接。 client告知server,我要下载哪个文件。 server将文件传输给client。 其中实现了两种server,一种是通过SendFile发送文件,一种是通过普通的Socket方式发送文件。具体代码如下: client.cpp:client端,文件接收端 //Client端 #include <arpa/inet.h> #include <netinet/in.h> #include <sys/types

Django download file empty

做~自己de王妃 提交于 2019-12-06 12:01:19
I am writing a simple function for downloading a certain file, from the server, to my machine. The file is unique represented by its id. The file is locatd corectly, and the download is done, but the downloaded file (though named as the one on the server) is empty. my download function looks like this: def download_course(request, id): course = Courses.objects.get(pk = id).course path_to_file = 'root/cFolder' filename = __file__ # Select your file here. wrapper = FileWrapper(file(filename)) content_type = mimetypes.guess_type(filename)[0] response = HttpResponse(wrapper, content_type = content

Linux >2.6.33: could sendfile() be used to implement a faster 'cat'?

独自空忆成欢 提交于 2019-12-06 09:45:49
Having to concatenate lots of large files into an even larger single one, we currently use cat file1 file2 ... output_file but are wondering whether it could be done faster than with that old friend. Reading the man page of sendfile() , one can specify an offset into *input_file*, from where to send the remainder of it to *output_file*. But: can I also specify an offset into *output_file*? Or could I simply loop over all input files, simply by leaving open my output FD and sendfile()'ing repeatedly into it, effectively concatenating the *input_files*? In other words: would the filepointer into

sendfile64 only copy about 2GB

☆樱花仙子☆ 提交于 2019-12-06 03:11:01
问题 I need to use sendfile64 to copy about 16GB of files. What I have achieved so far is #include <unistd.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <fcntl.h> #include <stdlib.h> #include <sys/sendfile.h> #include <sys/stat.h> int main (int argc, char** argv) { long long src; long long dest; struct stat64 stat_buf; off64_t offset = 0LL; long long rc; if (argc != 3) { fprintf(stderr, "usage: %s <source> <destination>\n", argv[0]); exit(1); } src = open64(argv[1], O