Struct async_graphql::types::Upload [−][src]
pub struct Upload(_);
Expand description
Uploaded file
Reference: https://github.com/jaydenseric/graphql-multipart-request-spec
Graphql supports file uploads via multipart/form-data
.
Enable this feature by accepting an argument of type Upload
(single file) or
Vec<Upload>
(multiple files) in your mutation like in the example blow.
Example
use async_graphql::*;
struct Mutation;
#[Object]
impl Mutation {
async fn upload(&self, ctx: &Context<'_>, file: Upload) -> bool {
println!("upload: filename={}", file.value(ctx).unwrap().filename);
true
}
}
Example Curl Request
Assuming you have defined your Mutation like in the example above,
you can now upload a file myFile.txt
with the below curl command:
curl 'localhost:8000' \
--form 'operations={
"query": "mutation ($file: Upload!) { upload(file: $file) }",
"variables": { "file": null }}' \
--form 'map={ "0": ["variables.file"] }' \
--form '0=@myFile.txt'
Implementations
Get the upload value.
Trait Implementations
type RawValueType = Self
type RawValueType = Self
The raw type used for validator. Read more
Create type information in the registry and return qualified typename.
Parse from Value
. None represents undefined.
Returns a reference to the raw value.
Qualified typename.
Auto Trait Implementations
impl RefUnwindSafe for Upload
impl UnwindSafe for Upload
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more