quickblox-javascript-sdk icon indicating copy to clipboard operation
quickblox-javascript-sdk copied to clipboard

download attachents with content functions

Open hi-kuldeep opened this issue 4 years ago • 1 comments

image image image

When i use

<a href="privateUrl" download> <img="privateUrl" /> </a>

image

How i can download attachments (pdf / image / docs)?? please help

hi-kuldeep avatar May 03 '21 08:05 hi-kuldeep

Hi @hi-kuldeep . You can try following code to download attachment(s):

const privateUrl = QB.content.privateUrl('your file id');
const [url, token] = privateUrl.split('?token=');
fetch(url + '.json', {
  headers: { 'QB-Token': token }
})
.then(res => res.blob())
.then(blob => {
  const a = document.createElement('a');
  const blobUrl = URL.createObjectURL(blob);
  a.href = URL.createObjectURL(blob);
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
  URL.revokeObjectURL(blobUrl);
})

ghost avatar Oct 05 '21 10:10 ghost