You're viewing documentation for a version of this software that is in development. Switch to the latest stable version
/
Launch Apollo Studio

Uploading files


Apollo Android supports file uploading over graphql-multipart-request-spec.

You need to define this mapping in your build.gradle file.

apollo {
  customScalarsMapping = [
    "Upload" : "com.apollographql.apollo3.api.Upload"
  ]
}

In this example, the GraphQL schema uses custom scalar type named Upload for file upload. Change it to match your GraphQL schema.

You don't need to register a custom type adapter for Upload, the runtime will recognize it and use the appropriate adapter.

Create graphql mutation.

mutation SingleUpload($file: Upload!) {
  singleUpload(file: $file) {
    id
    path
    filename
    mimetype
  }
}

Create an instance of Upload using one of the factory methods:

val upload = Upload.fromSource(okioSource)
// or if you're on the JVM
val upload = Upload.fromFile(file)

And execute your mutation:

val response = apolloClient.mutate(SingleUploadMutation(file = upload))
Edit on GitHub