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 following the GraphQL multipart request specification.

First, add the following custom scalar mapping to the Apollo Gradle plugin configuration:

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

In this example, the GraphQL schema defines a custom scalar type named Upload - adapt it to match your own GraphQL schema.

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

Now let's consider a mutation that takes an Upload as a parameter:

mutation SingleUpload($file: Upload!) {
  singleUpload(file: $file) {

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.mutation(SingleUploadMutation(file = upload)).execute()
Edit on GitHub