pub struct Download { /* private fields */ }http only.Expand description
Raw bytes, with their own media type — a file, not a document.
The one response in this crate that is deliberately not
application/vnd.api+json. A resource’s bytes are not a JSON:API
document and wrapping them in one would mean base64 in an attribute,
which doubles the transfer and cannot be streamed or ranged.
The conventional shape, and the one CONTENT routes: the
resource stays a JSON document carrying metadata at /docs/{id}, and its
bytes live beside it at /docs/{id}/content.
use ash_jsonapi::response::Download;
let file = Download::new(vec![0x89, b'P', b'N', b'G'], "image/png")
.filename("diagram.png");Implementations§
Source§impl Download
impl Download
Sourcepub fn new(bytes: impl Into<Vec<u8>>, content_type: impl Into<String>) -> Self
pub fn new(bytes: impl Into<Vec<u8>>, content_type: impl Into<String>) -> Self
Bytes, and the media type to serve them as.
The media type is the caller’s: this crate does not sniff content,
because guessing a type from bytes is how an uploaded HTML file comes
back as text/html and runs as the origin.
Sourcepub fn filename(self, filename: impl Into<String>) -> Self
pub fn filename(self, filename: impl Into<String>) -> Self
Suggest a filename, and ask the browser to save rather than render.
Sets Content-Disposition: attachment. The name is escaped — see
disposition.
Sourcepub fn inline(self) -> Self
pub fn inline(self) -> Self
Render in the browser rather than downloading, keeping any filename.
Content-Disposition: inline — for an image or a PDF a user expects
to see rather than save. Off by default: attachment is the safer
choice, since it does not invite the browser to interpret the bytes.