Upload local files

Upload local files to Pinnacle to send as messages.

Python

Our Python SDK rcs-py provides both a synchronous and an asynchronous method to upload files to Pinnacle. The upload(self, file_path: str) takes in a local file path that is uploaded and return a download URL that can be used as the media url for messages. The upload method can be used in both synchronous and asynchronous mode depending on the type of PinnacleClient that is used.

Synchronous

1import os
2from rcs.client import Pinnacle, AsyncPinnacle
3
4client = Pinnacle(api_key="YOUR_API_KEY")
5
6test_file_path = os.path.join(
7 os.path.dirname(__file__), "test.csv"
8)
9
10download_url = client.upload(test_file_path)
11client.send.mms(from_="FROM_NUMBER", to="TO_NUMBER", media_urls=[download_url])

Asynchronous

1client = AsyncPinnacle(api_key="YOUR_API_KEY")
2
3test_file_path = os.path.join(
4 os.path.dirname(__file__), "test.csv"
5)
6
7download_url = await client.upload(test_file_path)
8await client.send.mms(
9 from_="FROM_NUMBER", to="TO_NUMBER", media_urls=[download_url]
10)

TypeScript

Our TypeScript SDK rcs-js provides a method to upload files to Pinnacle. The async upload method takes in a File object and return a download URL that can be used as the media url for messages.

1import { PinnacleClient, Pinnacle } from "rcs-js";
2import fs from "fs";
3import path from "path";
4
5// Create a File object from a local file
6const filePath = path.join(__dirname, "test.csv");
7const fileContent = fs.readFileSync(filePath);
8const file = new File([fileContent], "test.csv", {
9 type: "text/csv",
10 lastModified: Date.now(),
11});
12
13const client = new PinnacleClient({
14 apiKey: "YOUR_API_KEY",
15});
16
17const downloadUrl = await client.upload(file);
18await client.send.mms({
19 from: "FROM_NUMBER",
20 to: "TO_NUMBER",
21 mediaUrls: [downloadUrl],
22});

Other languages

At this time, this upload functionality is not natively supported in other languages (notably Ruby). However, you can still use the Create Upload URL which generates a presigned upload URL (to upload your media asset) and also a download URL (to use as the media URL in your message).

To do so, first create the upload and download URLs using the POST /tools/upload-url endpoint.

1require 'rest-client'
2require 'json'
3
4response = RestClient.post(
5 'https://www.trypinnacle.dev/api/tools/uploadUrl',
6 {
7 contentType: "image/png",
8 size: 1024,
9 name: "example.png"
10 }.to_json,
11 {
12 "PINNACLE-API-Key": "<apiKey>",
13 content_type: :json,
14 accept: :json
15 }
16)
17upload_url = JSON.parse(response.body)["upload"]
18download_url = JSON.parse(response.body)["download"]

Then, make a PUT request to the upload URL with the proper content_type header to upload the file to Pinnacle.

1response = RestClient.put(
2 upload_url,
3 File.read("example.png"),
4 {
5 content_type: "image/png",
6 accept: :json
7 }
8)

Finally, use the download URL as the media URL in your message.

1require "rcs"
2api = Pinnacle::Client.new(
3 api_key: "YOUR_API_KEY"
4)
5api.send.mms(
6 to: "TO_NUMBER",
7 from: "FROM_NUMBER",
8 media_urls: [download_url]
9)