curl --request POST \
--url https://api-dev.narrative.io/uploads/{upload_path} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api-dev.narrative.io/uploads/{upload_path}"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api-dev.narrative.io/uploads/{upload_path}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-dev.narrative.io/uploads/{upload_path}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api-dev.narrative.io/uploads/{upload_path}"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-dev.narrative.io/uploads/{upload_path}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/uploads/{upload_path}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"path": "d295d6fd3d9c32462d89cf8270cca4cbb95cc660ada5cfc59c5a7458bd941d9c.csv",
"url": "https://narrative-file-upload.s3.amazonaws.com/companyId%3D1/d295d6fd3d9c32462d89cf8270cca4cbb95cc660ada5cfc59c5a7458bd941d9c.csv?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210122T151716Z&X-Amz-SignedHeaders=host&X-Amz-Expires=1799&X-Amz-Signature=3c1e45b6d8827b7158a6157dbc548fdf263c2f23f731117056058f489b26c64b",
"expiry": "2021-01-22T15:47:16.036Z"
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}Upload a file
Sending a file to Narrative is a two step process. This endpoint allows you to request an upload_url which can be used in a PUT request to upload the file.
For example, once you have received an upload_url you could use it as follows:
curl -v --upload-file my-file.csv {upload_url}
The generated upload_url is only valid for 30 minutes after issuance.
Narrative stores the file under the SHA-256 hash of upload_path and returns that name as path. When
upload_path ends in one of the following extensions, the stored name keeps the extension in lowercase:
txt, csv, json, parquet and snappy.parquet, plus txt, csv and json followed by .gz or .bz2.
Any other extension is dropped. For example, lists/idlist.csv is stored as
d295d6fd3d9c32462d89cf8270cca4cbb95cc660ada5cfc59c5a7458bd941d9c.csv.
The hash is taken over upload_path exactly as it was sent, so the same upload_path always names the same
file, and uploading to it again replaces that file. A slash sent as %2F hashes differently from a literal /.
Requires write access to uploads.
curl --request POST \
--url https://api-dev.narrative.io/uploads/{upload_path} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api-dev.narrative.io/uploads/{upload_path}"
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api-dev.narrative.io/uploads/{upload_path}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-dev.narrative.io/uploads/{upload_path}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api-dev.narrative.io/uploads/{upload_path}"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-dev.narrative.io/uploads/{upload_path}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/uploads/{upload_path}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"path": "d295d6fd3d9c32462d89cf8270cca4cbb95cc660ada5cfc59c5a7458bd941d9c.csv",
"url": "https://narrative-file-upload.s3.amazonaws.com/companyId%3D1/d295d6fd3d9c32462d89cf8270cca4cbb95cc660ada5cfc59c5a7458bd941d9c.csv?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210122T151716Z&X-Amz-SignedHeaders=host&X-Amz-Expires=1799&X-Amz-Signature=3c1e45b6d8827b7158a6157dbc548fdf263c2f23f731117056058f489b26c64b",
"expiry": "2021-01-22T15:47:16.036Z"
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
A path for the file, such as its path on your machine, which may contain slashes. Narrative uses upload_path
only to name the stored file, which is the SHA-256 hash of upload_path plus the file's extension when Narrative
recognizes it.
Response
The upload url
The name the file is stored under. It is the SHA-256 hash of upload_path in hex, followed by the file's
extension when Narrative recognizes it.
"d295d6fd3d9c32462d89cf8270cca4cbb95cc660ada5cfc59c5a7458bd941d9c.csv"
The presigned S3 URL to PUT the file to.
"https://narrative-file-upload.s3.amazonaws.com/companyId%3D1/d295d6fd3d9c32462d89cf8270cca4cbb95cc660ada5cfc59c5a7458bd941d9c.csv?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210122T151716Z&X-Amz-SignedHeaders=host&X-Amz-Expires=1799&X-Amz-Signature=3c1e45b6d8827b7158a6157dbc548fdf263c2f23f731117056058f489b26c64b"
When url stops accepting the upload, 30 minutes after it was issued.
"2021-01-22T15:47:16.036Z"
Was this page helpful?

