Fetching files from storage is achieved by using History API in combination with Files SDK methods:
- Obtain the file message using History API, or listFiles method.
History API response doesn't include file URL. It returns file details (ID, filename) and a message type of4
, indicating a file message. This information is used for file retrieval. - Display/download the file using SDK methods based on the obtained file information.
The code below is used to create a file URL that allows you to display the file in your browser:
Javascript//
const result = pubnub.getFileUrl({
channel: 'my_channel',
id: '1234',
name: 'picture.jpg'
});
To download a file, the same file information is used along with file URL information:
const file = await pubnub.downloadFile({
channel: 'my_channel',
id: '1234',
name: 'picture.jpg',
});
const myImageTag = document.createElement('img');
myImageTag.src = URL.createObjectURL(await file.toFile());
document.body.appendChild(myImageTag);
For more information, please check:
In case of any questions, please reach out to support@pubnub.com.