Upload and download
Short answer
Upload a file by sending its bytes to POST /v2/files/upload with the path it should have; missing folders are created for you. Fetch copies a file from any URL into your account. For very large files, use resumable tus uploads. Download returns the original file. Each command needs a bearer token.
After reading this you will know
- How to upload a file, or fetch one from a URL
- How to upload large files with resumable tus uploads
- How to download the original of any file
Every command on this page needs a bearer token.
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.
Fetch URL
Section titled “Fetch URL”https://api.sirv.com/v2/files/fetch
Use this API method to fetch a file(s) from a URL via HTTP and save it to your Sirv account.
This can be any URL, either public or private (via HTTP authentication). In the url parameter, enter the full URL of the remote file.
In the filename parameter, enter the folder path and filename where it should be saved e.g. /path/to/folder/new-filename.jpg.
If the folder path does not already exist in your Sirv account new folder(s) will be created.
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/fetch', { method: 'POST', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' }, body: JSON.stringify([ { "url": "https://demo.sirv.com/aurora.jpg", "filename": "/REST API Examples/aurora.jpg" }, { "url": "https://demo.sirv.com/missing.jpg", "filename": "/REST API Examples/missing.jpg" } ]),});console.log(res.status, await res.text());import requests
res = requests.post( 'https://api.sirv.com/v2/files/fetch', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json=[ { "url": "https://demo.sirv.com/aurora.jpg", "filename": "/REST API Examples/aurora.jpg" }, { "url": "https://demo.sirv.com/missing.jpg", "filename": "/REST API Examples/missing.jpg" } ],)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/files/fetch' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '[{"url":"https://demo.sirv.com/aurora.jpg","filename":"/REST API Examples/aurora.jpg"},{"url":"https://demo.sirv.com/missing.jpg","filename":"/REST API Examples/missing.jpg"}]'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/fetch")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" [ { "url": "https://demo.sirv.com/aurora.jpg", "filename": "/REST API Examples/aurora.jpg" }, { "url": "https://demo.sirv.com/missing.jpg", "filename": "/REST API Examples/missing.jpg" } ] """)) .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("POST"), "https://api.sirv.com/v2/files/fetch");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""[ { "url": "https://demo.sirv.com/aurora.jpg", "filename": "/REST API Examples/aurora.jpg" }, { "url": "https://demo.sirv.com/missing.jpg", "filename": "/REST API Examples/missing.jpg" }]""", System.Text.Encoding.UTF8, "application/json");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/fetch');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode([ [ 'url' => 'https://demo.sirv.com/aurora.jpg', 'filename' => '/REST API Examples/aurora.jpg' ], [ 'url' => 'https://demo.sirv.com/missing.jpg', 'filename' => '/REST API Examples/missing.jpg' ] ]), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`[ { "url": "https://demo.sirv.com/aurora.jpg", "filename": "/REST API Examples/aurora.jpg" }, { "url": "https://demo.sirv.com/missing.jpg", "filename": "/REST API Examples/missing.jpg" } ]`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/fetch", body) req.Header.Set("authorization", "Bearer BEARER_TOKEN") req.Header.Set("content-type", "application/json") 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/fetch')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' [ { "url": "https://demo.sirv.com/aurora.jpg", "filename": "/REST API Examples/aurora.jpg" }, { "url": "https://demo.sirv.com/missing.jpg", "filename": "/REST API Examples/missing.jpg" } ]JSONres = 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/fetch")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""[ { "url": "https://demo.sirv.com/aurora.jpg", "filename": "/REST API Examples/aurora.jpg" }, { "url": "https://demo.sirv.com/missing.jpg", "filename": "/REST API Examples/missing.jpg" }]"""#.data(using: .utf8)let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Example response
[ { "filename": "/REST API Examples/aurora.jpg", "success": true, "attempted": false, "attempts": [ { "url": "https://demo.sirv.com/aurora.jpg", "initiator": { "type": "api", "remoteAddr": "176.105.166.4", "date": "2020-07-17T15:47:35.316Z" }, "statusCode": 200, "headers": { "result": { "version": "HTTP/1.1", "code": 200, "reason": "OK" }, "Date": "Fri, 17 Jul 2020 15:47:36 GMT", "Content-Type": "image/webp", "Content-Length": "201846", "Connection": "keep-alive", "Last-Modified": "Fri, 17 Jul 2020 15:47:36 GMT", "ETag": "\"5f11c818-31476\"", "Server": "Sirv.Imagination", "X-Sirv-Server": "c1-extra1-fireball-13", "X-Sirv-Cache": "MISS", "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "*", "Expires": "Sun, 16 Aug 2020 15:47:36 GMT", "Cache-Control": "max-age=2592000", "X-Sirv-Meta-Width": "2500", "X-Sirv-Meta-Height": "1667", "X-Sirv-Shard": "c1-riak1", "X-Account-Id": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud", "X-File-VersionId": "5evxYG8lnBgeA7cGBRTZzq7JQolRYviN:0", "X-Account-Serial": "2020-06-15T19:18:53.901Z", "Accept-Ranges": "bytes" }, "timing": { "ns": 0.007514, "connect": 0.007912, "start": 0.48724, "total": 0.489622 }, "date": "2020-07-17T15:47:36.712Z" } ], "retryAfter": "2020-07-18T15:47:36.712Z" }, { "filename": "/REST API Examples/missing.jpg", "success": false, "attempted": false, "attempts": [ { "url": "https://demo.sirv.com/missing.jpg", "initiator": { "type": "api", "remoteAddr": "176.105.166.4", "date": "2020-07-18T08:35:51.026Z" }, "statusCode": 404, "headers": { "result": { "version": "HTTP/1.1", "code": 404, "reason": "Not Found" }, "Date": "Sat, 18 Jul 2020 08:35:52 GMT", "Content-Type": "text/html; charset=utf-8", "Content-Length": "4140", "Connection": "keep-alive", "Vary": "Accept-Encoding", "X-Account-Id": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud", "X-Account-Serial": "2020-06-15T19:18:53.901Z", "ETag": "W/\"102c-wKpRt+Cg9Cnw/NpTSkF5+w\"", "X-Sirv-Cache": "MISS", "Server": "Sirv.Imagination", "X-Sirv-Server": "c1-extra1-fireball-15", "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "*" }, "timing": { "ns": 0.018986, "connect": 0.019303, "start": 0.103774, "total": 0.103829 }, "error": { "name": "Error", "message": "Request not successful: expected status code 200 but got 404" }, "date": "2020-07-18T08:35:52.089Z" } ], "retryAfter": "2020-07-18T12:07:32.613Z" }]Get tus.io upload link
Section titled “Get tus.io upload link”https://api.sirv.com/v2/files/tus/url
Use this API method to get a link for uploading a file with tus.io.
tus.io uploads send a file in chunks of up to 1 MB, can resume after a broken connection and take files up to 1 GB. The link works for 1 hour unless you set expiresIn, up to 7 days.
Use the link as the endpoint of a tus.io client and give the file’s path in metadata.filename. The file shows in your account 1 to 4 seconds after the upload ends. The steps are in tus.io multipart uploads.
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
location | string | Yes | gb_london | Upload server to send the file to, from List available tus.io locations. |
expiresIn | number | No | 18000 | URL expiration time in seconds |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/tus/url?location=gb_london&expiresIn=18000', { 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/tus/url?location=gb_london&expiresIn=18000', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/files/tus/url?location=gb_london&expiresIn=18000' \ --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/tus/url?location=gb_london&expiresIn=18000")) .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/tus/url?location=gb_london&expiresIn=18000");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/tus/url?location=gb_london&expiresIn=18000');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/tus/url?location=gb_london&expiresIn=18000", 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/tus/url?location=gb_london&expiresIn=18000')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/tus/url?location=gb_london&expiresIn=18000")!)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))Example response
{ "url": "https://sirvcdn-gbr-4.sirv.com:444/upload/eyJhbhoaigGSiuhgkahFFGnX0"}List available tus.io locations
Section titled “List available tus.io locations”https://api.sirv.com/v2/files/tus/locations
Use this API method to list available tus.io locations.
Each location is an upload server near one city. Pick the one closest to you, then ask for an upload link with Get tus.io upload link. How tus.io uploads work is explained in tus.io multipart uploads.
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/tus/locations', { 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/tus/locations', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/files/tus/locations' \ --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/tus/locations")) .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/tus/locations");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/tus/locations');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/tus/locations", 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/tus/locations')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/tus/locations")!)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))Example response
[ "au_sydney", "br_sao_paulo", "ca_monreal", "de_falkenstein", "fi_helsinki", "fr_paris", "gb_london", "hk_hong_kong", "in_mumbai", "kr_seoul", "nz_christchurch", "sg_singapore", "us_atlanta", "us_buffalo", "us_chicago", "us_dallas", "us_kansas", "us_los_angeles", "us_miami", "us_phoenix", "us_seattle", "us_washington", "za_capetown"]Upload file
Section titled “Upload file”https://api.sirv.com/v2/files/upload
Use this API method to upload a file. If the folder path does not already exist, it will be created. Specify the appropriate content type.
Use binary content encoding (not base64).
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
filename | string | Yes | /REST API Examples/uploaded.txt | Path to save the file at, with its name. Missing folders are created. |
Example request
import { readFile } from 'node:fs/promises';
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/files/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt', { method: 'POST', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'image/jpeg' }, body: await readFile('image.jpg'),});console.log(res.status, await res.text());import requests
res = requests.post( 'https://api.sirv.com/v2/files/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'image/jpeg'}, data=open('image.jpg', 'rb'),)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/files/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: image/jpeg' \ --data-binary @image.jpgimport java.net.URI;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;import java.nio.file.Path;
HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/files/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "image/jpeg") .method("POST", HttpRequest.BodyPublishers.ofFile(Path.of("image.jpg"))) .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("POST"), "https://api.sirv.com/v2/files/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new ByteArrayContent(File.ReadAllBytes("image.jpg"));request.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");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/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: image/jpeg'], CURLOPT_POSTFIELDS => file_get_contents('image.jpg'), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "os")
func main() { body, _ := os.Open("image.jpg") defer body.Close() req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/files/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt", body) req.Header.Set("authorization", "Bearer BEARER_TOKEN") req.Header.Set("content-type", "image/jpeg") 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/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'image/jpeg'req.body = File.binread('image.jpg')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/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("image/jpeg", forHTTPHeaderField: "content-type")request.httpBody = try Data(contentsOf: URL(fileURLWithPath: "image.jpg"))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.
