Uploading Files

  • The Google Play Developer API supports uploading images, apks, or expansion files for an edit using specific API methods that support media uploads.

  • You can choose from three upload types: Simple for small files, Multipart for small files with metadata, and Resumable for reliable transfers, especially important for larger files.

  • Methods supporting media uploads use a special "/upload" URI for the media data and the standard resource URI for metadata.

  • Resumable upload involves starting a session, saving the session URI, uploading the file (potentially in chunks), and includes a procedure for resuming interrupted uploads.

  • Best practices for uploading media include resuming or retrying uploads that fail due to connection issues or 5xx errors and using exponential backoff for server errors.

The Google Play Developer API allows you to upload images, apks or expansionfiles for an edit. Below we use images as an example.

Upload options

The Google Play Developer API allows you to upload certain types of binary data, or media. The specific characteristics of the data you can upload are specified on the reference page for any method that supports media uploads:

  • Maximum upload file size: The maximum amount of data you can store with this method.
  • Accepted media MIME types: The types of binary data you can store using this method.

You can make upload requests in any of the following ways. Specify the method you are using with the uploadType request parameter.

  • Simple upload: uploadType=media. For quick transfer of smaller files, for example, 5 MB or less.
  • Multipart upload: uploadType=multipart. For quick transfer of smaller files and metadata; transfers the file along with metadata that describes it, all in a single request.
  • Resumable upload: uploadType=resumable. For reliable transfer, especially important with larger files. With this method, you use a session initiating request, which optionally can include metadata. This is a good strategy to use for most applications, since it also works for smaller files at the cost of one additional HTTP request per upload.

When you upload media, you use a special URI. In fact, methods that support media uploads have two URI endpoints:

  • The /upload URI, for the media. The format of the upload endpoint is the standard resource URI with an “/upload” prefix. Use this URI when transferring the media data itself.

    Example: POST /upload/androidpublisher/v3/applications/packageName/edits/editId/listings/language/imageType

  • The standard resource URI, for the metadata. If the resource contains any data fields, those fields are used to store metadata describing the uploaded file. You can use this URI when creating or updating metadata values.

    Example: POST /androidpublisher/v3/applications/packageName/edits/editId/listings/language/imageType

Simple upload

The most straightforward method for uploading a file is by making a simple upload request. This option is a good choice when:

  • The file is small enough to upload again in its entirety if the connection fails.
  • There is no metadata to send. This might be true if you plan to send metadata for this resource in a separate request, or if no metadata is supported or available.

To use simple upload, make a POST or PUT request to the method's /upload URI and add the query parameter uploadType=media. For example:

POST https://www.googleapis.com/upload/androidpublisher/v3/applications/packageName/edits/editId/listings/language/imageType?uploadType=media

The HTTP headers to use when making a simple upload request include:

  • Content-Type. Set to one of the method's accepted upload media data types, specified in the API reference.
  • Content-Length. Set to the number of bytes you are uploading. Not required if you are using chunked transfer encoding.

Example: Simple upload

The following example shows the use of a simple upload request for the Google Play Developer API.

POST /upload/androidpublisher/v3/applications/packageName/edits/editId/listings/language/imageType?uploadType=media HTTP/1.1
Host: www.googleapis.com
Content-Type: image/png
Content-Length: number_of_bytes_in_file
Authorization: Bearer your_auth_token

PNG data

If the request succeeds, the server returns the HTTP 200 OK status code along with any metadata:

HTTP/1.1 200
Content-Type: application/json

{
 
"image": {
   
"id": string,
   
"url": string,
   
"sha1": string
 
}
}

Multipart upload

If you have metadata that you want to send along with the data to upload, you can make a single multipart/related request. This is a good choice if the data you are sending is small enough to upload again in its entirety if the connection fails.

To use multipart upload, make a POST or PUT request to the method's /upload URI and add the query parameter uploadType=multipart, for example:

POST https://www.googleapis.com/upload/androidpublisher/v3/applications/packageName/edits/editId/listings/language/imageType?uploadType=multipart

The top-level HTTP headers to use when making a multipart upload request include:

  • Content-Type. Set to multipart/related and include the boundary string you're using to identify the parts of the request.
  • Content-Length. Set to the total number of bytes in the request body. The media portion of the request must be less than the maximum file size specified for this method.

The body of the request is formatted as a multipart/related content type [RFC2387] and contains exactly two parts. The parts are identified by a boundary string, and the final boundary string is followed by two hyphens.

Each part of the multipart request needs an additional Content-Type header:

  1. Metadata part: Must come first, and Content-Type must match one of the accepted metadata formats.
  2. Media part: Must come second, and Content-Type must match one the method's accepted media MIME types.

See the API reference for each method's list of accepted media MIME types and size limits for uploaded files.

Note: To create or update the metadata portion only, without uploading the associated data, simply send a POST or PUT request to the standard resource endpoint: https://www.googleapis.com/androidpublisher/v3/applications/packageName/edits/editId/listings/language/imageType

Example: Multipart upload

The example below shows a multipart upload request for the Google Play Developer API.

POST /upload/androidpublisher/v3/applications/packageName/edits/editId/listings/language/imageType?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer your_auth_token
Content-Type: multipart/related; boundary=foo_bar_baz
Content-Length: number_of_bytes_in_entire_request_body

--foo_bar_baz
Content-Type: application/json; charset=UTF-8

{
 
"image": {
   
"id": string,
   
"url": string,
   
"sha1": string
 
}
} --foo_bar_baz Content-Type: image/png PNG data --foo_bar_baz--

If the request succeeds, the server returns the HTTP 200 OK status code along with any metadata:

HTTP/1.1 200
Content-Type: application/json

{
 
"image": {
   
"id": string,
   
"url": string,
   
"sha1":