跳至内容 跳至搜索

Action Dispatch HTTP 上传文件

模型上传文件。

实际文件可以通过 tempfile 访问器访问,但为了方便起见,部分接口可以直接使用。

上传文件是临时文件,其生命周期为一个请求。当对象完成时,Ruby 会解除文件的链接,因此无需使用单独的维护任务来清理它们。

方法
C
E
O
P
R
S
T

属性

[RW] content_type

包含文件 MIME 类型的字符串。

[RW] headers

包含多部分请求标头的字符串。

[RW] original_filename

客户端中文件的基名。

[RW] tempfile

包含实际上传文件的 Tempfile 对象。请注意,部分接口可以直接使用。

实例公共方法

close(unlink_now = false)

tempfile.close 的快捷方式。

# File actionpack/lib/action_dispatch/http/upload.rb, line 71
def close(unlink_now = false)
  @tempfile.close(unlink_now)
end

eof?()

tempfile.eof? 的快捷方式。

# File actionpack/lib/action_dispatch/http/upload.rb, line 96
def eof?
  @tempfile.eof?
end

open()

tempfile.open 的快捷方式。

# File actionpack/lib/action_dispatch/http/upload.rb, line 66
def open
  @tempfile.open
end

path()

tempfile.path 的快捷方式。

# File actionpack/lib/action_dispatch/http/upload.rb, line 76
def path
  @tempfile.path
end

read(length = nil, buffer = nil)

tempfile.read 的快捷方式。

# File actionpack/lib/action_dispatch/http/upload.rb, line 61
def read(length = nil, buffer = nil)
  @tempfile.read(length, buffer)
end

rewind()

tempfile.rewind 的快捷方式。

# File actionpack/lib/action_dispatch/http/upload.rb, line 86
def rewind
  @tempfile.rewind
end

size()

tempfile.size 的快捷方式。

# File actionpack/lib/action_dispatch/http/upload.rb, line 91
def size
  @tempfile.size
end

to_io()

# File actionpack/lib/action_dispatch/http/upload.rb, line 100
def to_io
  @tempfile.to_io
end

to_path()

tempfile.to_path 的快捷方式。

# File actionpack/lib/action_dispatch/http/upload.rb, line 81
def to_path
  @tempfile.to_path
end