download method

Request<TrackPhotoDownload> download(
  1. String id, {
  2. Uri? location,
})

Track a photo download

To abide by the API guidelines, you need to trigger a GET request to this endpoint every time your application performs a download of a photo. To understand what constitutes a download, please refer to the ‘Triggering a download’ guideline.

This is purely an event endpoint used to increment the number of downloads a photo has. You can think of it very similarly to the pageview event in Google Analytics—where you’re incrementing a counter on the backend. This endpoint is not to be used to embed the photo (use the photo.urls.* properties instead) or to direct the user to the downloaded photo (use the photo.urls.full instead), it is for tracking purposes only.

To follow the guidelines you should pass the Photo.links.downloadLocation to location, to include all the necessary information.

See: Unsplash docs

Implementation

Request<TrackPhotoDownload> download(String id, {Uri? location}) {
  final url = baseUrl
      .resolve('$id/download')
      .replace(queryParameters: location?.queryParameters ?? const {});

  return Request(
    client: client,
    httpRequest: http.Request('GET', url),
    isPublicAction: true,
    bodyDeserializer: (dynamic json) =>
        TrackPhotoDownload.fromJson(json as Map<String, dynamic>),
  );
}