开发者

Saving the file on a user selected location using rails

We are developing a functionality that allows the users to save the downloaded file. We are struggling to get a popup where the 开发者_JAVA百科user can select a target location / folder to save his file. Can this be achieved using rails?


I think you're looking for send_file - it's very easy to use.


I think it depends on the content-type and similar headers you're returning to the user. Try returning something like:

header('Content-disposition: attachment; filename=movie.mpg');
header('Content-type: video/mpeg');

EDIT: I am assuming you're able to generate headers and returning a file to the user by HTTP (no simple links to files)


I think you are trying to give something like file browser dialog box which allows client to save file on a particular location.

In case you are trying to give this from your server then I should say it is not possible due to security restriction which browser makers have applied to ensure client's security.

Another way is to let client download your browser plugin/activeX Control which basically is control over client's machine then you can do what you want i.e. something like this also.

I think without this the filetype downloaded by client is identified (based on headers) by browser and it opens the file save dialog box automatically and you cant enter into client's secure arena.


I think you want download file option. For example on hitting a URL you want user to download a zip file code for it you can do something like this:

class MyController < ApplicationController
  def downloadzip
     send_file "path_to_file", :type=>"application/zip"
   end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜