Class: RubstApi::FileResponse

Inherits:
StreamingResponse show all
Defined in:
lib/rubst_api/responses.rb

Instance Attribute Summary

Attributes inherited from Response

#body, #headers, #media_type, #status_code

Instance Method Summary collapse

Methods inherited from StreamingResponse

#finish

Methods inherited from Response

#delete_cookie, #finish, #render, #set_cookie

Constructor Details

#initialize(path, filename: nil, media_type: "application/octet-stream", **options) ⇒ FileResponse

Returns a new instance of FileResponse.



52
53
54
55
56
# File 'lib/rubst_api/responses.rb', line 52

def initialize(path, filename: nil, media_type: "application/octet-stream", **options)
  headers = options.delete(:headers) || {}
  headers["content-disposition"] = %(attachment; filename="#{filename}") if filename
  super(File.open(path, "rb"), media_type:, headers:, **options)
end