Files
The Extra Horizon SDK can be used on different platforms, each handling binary data slightly different. So we've collected a few examples on how to upload/download binary data for each of the supported platforms.
Web
In browsers the File and Blob classes can be used for uploads.
A download results in an ArrayBuffer.
File upload example
const fileInputElement = document.querySelector('input[type="file"]');
const file = fileInputElement.files[0];
const uploadResult = await exh.files.create(file.name, file);Blob upload example
const content = 'Hello, world!';
const fileName = 'example.txt';
const mimeType = 'text/plain';
const blob = new Blob([content], { type: mimeType });
const uploadResult = await exh.files.create(fileName, blob);Download example
React Native
Currently React Native provides limited support for binary data upload using FormData. As this is the basis for our file upload, for now only uploading from the file system is properly supported.
A download results in an ArrayBuffer.
Upload example expo-file-system
https://docs.expo.dev/versions/latest/sdk/filesystem/
Upload example expo-image-picker
https://docs.expo.dev/versions/latest/sdk/imagepicker/
Download example
Node.js
The form-data package is used to allow strings, buffers and streams to be uploaded.
A download results in a Buffer.
String upload example
Buffer upload example
Stream upload example
Buffer download example
Stream download example
Abort request example
Last updated