views:

22

answers:

2

Can I use send_file to send a file on a drive other than the Rails.root drive? I've tried both options below. I need to use the second option but Rails doesn't like using a drive other than the volume on which it is on.

This works:

def action
  send_file "C:\\rails_root\\public\\files\\file.ext"
end

This doesn't:

def action
  send_file "D:\\files\\file.ext"
end

Is send_file restricted to just the Rails.root drive? Is it possible to serve static files from a directory on a network mapped drive? Oh, and this is (un)fortunately an all windows environment.

UPDATE: So I've been digging around in the Rails/Ruby code that send_file uses and I think the primary culprit here is File.file?(path). It returns true when on the drive which Rails lives but false for networked drives.

UPDATE 2: Really strange. In the console both locations inserted for File.file?(path) return true. In the application running in the browser it returns false. I'm stumped.

A: 

Just a guess. Create a folder under the rails root, but not in piblic folder.

In this way, rails should be able to read it, but since it is not in public folder, others should have no way to direct access it.

Correct me if it's wrong.

PeterWong
I am trying to serve files from a mapped drive. So the rails app is on C:\app\ and I'm trying to serve files from a network attached drive at D:\files\. Some updates above help clarify the problem.
Nate Bird
Ooops, sorry for misunderstanding.
PeterWong
A: 

It turns out that the service running Apache didn't have permissions to access the network share.

In the controller I ended up using the direct network share address instead of using the mapped drive. I'm still not sure why the mapped drive didn't work.

def download
   send_file "\\\\server\\folder\file.ext"
end

In the Apache configuration file (domain.conf) you have to use forward slashes when setting the parameters for XSendFile.

XSendFile on
XSendFilePath //server/folder/

If anyone else has issues I'll be glad to try and help.

Nate Bird