Download a file
Short answer
Download a file with GET /v2/files/download. Give its path in the filename parameter and the API returns the original file as it was uploaded, not a resized or converted copy. Each call needs a bearer token and counts towards your hourly API limit. Below is the parameter and sample code in 9 languages.
After reading this you will know
- How to download a file
- Which parameters it takes
- Sample code in 9 languages and a sample answer
This command needs a bearer token and counts towards your hourly limit.
Download file
Section titled “Download file”https://api.sirv.com/v2/files/download
Use this API method to download a single file from an account.
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
filename | string | Yes | /REST API Examples/uploaded.txt | Path of the file to download. |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt', { method: 'GET', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },});console.log(res.status, await res.text());import requests
res = requests.get( 'https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt' \ --header 'authorization: Bearer BEARER_TOKEN'import java.net.URI;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;
HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt")) .header("authorization", "Bearer BEARER_TOKEN") .method("GET", HttpRequest.BodyPublishers.noBody()) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'], CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http")
func main() { req, _ := http.NewRequest("GET", "https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt", nil) req.Header.Set("authorization", "Bearer BEARER_TOKEN") res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() out, _ := io.ReadAll(res.Body) fmt.Println(res.Status, string(out))}require 'net/http'
uri = URI('https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt')req = Net::HTTP::Get.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt")!)request.httpMethod = "GET"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Response
HTTP 200 with an empty body when the command succeeds.