Skip to main content
Version: 1.x.x

Create an ImageRecord using an Image URL

Quip's support for the user to select and upload an image from their device is great, but sometimes you want to get an image from the web and store it into an ImageRecord.

Here's how you can achieve it:

Get the image using fetch and store the result as a blob

function getImage(url) {
return fetch(url)
.then(response => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.arrayBuffer();
})
.then(buffer => {
return new Blob([new Uint8Array(buffer)]);
});
}

Use ImageRecord's uploadFile method to store the data into the record:

const imageBlob = await getImage('https://image/url.png');
imageRecord.uploadFile(imageBlob);

See ImageRecord for a full description of the APIs.