import axios from './axios-instance'

function attachmentIdToBase64(id) {
  return new Promise((resolve, reject) => {
    axios({
      url: `api/framework/v1/task-form-process/download-attachments/${id}`,
      responseType: 'blob',
    })
      .then((res) => {
        const reader = new FileReader()
        reader.readAsDataURL(res.data)
        reader.addEventListener('load', () => {
          resolve(reader.result)
        })
      })
      .catch(() => {
        resolve('')
      })
  })
}

export default attachmentIdToBase64
