send_file

Function send_file 

Source
pub fn send_file(
    file_location: &str,
    file_name: Option<String>,
    file_type: FileType,
    http_code: u16,
    keep_alive: bool,
) -> Result<HttpResponse, Error>
Expand description

Create a new response object for file type responses.

§Parameters

  • file_location : Absolute location of a file.
  • file_name : Name of the file.When Client recieves the file this name will show.It can be left None,in that case name will be infered from path.
  • file_type : Type of the file. Don’t confuse it with std::fs::FileType. It’s a enum to indicate file format. e.g. FileType::MP4.
  • http_code : HTTP response Code.
  • keep_alive : Keep alive flag it can be true for persistent connection or false for non-persistent connection.

§Return

  • Result<HttpResponse,io::Error>

It returns an error if the HTTP code is not implimented. It returns 404 Not Found if the file doesn’t exists or Some error occurs while fetching file data.

§Example

use rastapi::{Response::send_file,utils::FileType};
let resp=send_file("absolute/path/to/file",Some("filename.mp4".to_string()),FileType::MP4,200,true).unwrap(); // resp is a HttpResponse type.