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 MutationRoot;
#[Object]
impl MutationRoot {
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 MutationRoot 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
Create type information in the registry and return qualified typename.
Qualified typename.
Introspection type name Read more
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
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