This guide shows how to retrieve recordings and download them to local storage. Plivo begins charging for stored recordings after 90 days. To avoid these charges, you can download recordings and store them elsewhere.
To use Plivo APIs, follow our instructions to set up a go development environment and a web server and safely expose that server to the internet.
Here’s sample code you can use to retrieve recordings to a local directory.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Example script for downloading recording files
package main
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"github.com/plivo/plivo-go/v7"
)
var (
AuthID = "<auth_id>"
AuthToken = "<auth_token>"
)
func main() {
client, err := plivo.NewClient(AuthID, AuthToken, &plivo.ClientOptions{})
if err != nil {
fmt.Println("Error", err.Error())
return
}
response, err := client.Recordings.List(
plivo.RecordingListParams{
AddTimeGreaterThan: "2023-04-01 00:00:00",
AddTimeLessThan: "2023-04-30 00:00:00",
Offset: 0,
Limit: 5,
},
)
if err != nil {
fmt.Println("Error", err.Error())
return
}
fmt.Printf("Found %d recordings.\n", len(response.Objects))
// Directory where the recordings will be saved
os.MkdirAll("recordings", os.ModePerm)
for _, recording := range response.Objects {
fmt.Println("Downloading recording: ", recording.RecordingURL)
filePath := filepath.Join("recordings", recording.RecordingID+recording.RecordingFormat)
err = downloadFile(filePath, recording.RecordingURL)
if err != nil {
fmt.Println("Error downloading file: ", err)
} else {
fmt.Println("Downloaded file to: ", filePath)
}
}
}
func downloadFile(filepath string, url string) error {
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
_, err = io.Copy(out, resp.Body)
return err
}
You can delete a recording by using the Delete a Recording API and specifying a recording ID, which you can retrieve from list all recordings API or the HTTP callback details stored in your database. You can also delete recordings from the Voice Recordings page of the Plivo console.