javascriptnode.jsreactjspasskitapple-wallet

Download and open pkpass from server in react


I have tried like everything but it isn't working. I am creating a apple wallet pass via https://github.com/walletpass/pass-js When I download it on the node serve where I have implement it, I am getting a valid pass and can load it to the wallet. But when I am download the pass through my react app I am getting a buffer. When decode that buffer I am getting the (looks like) same data content like that from server. But when I am saving that stuff, the size is 113kb and not like the size of the pass I created on the server 65kb and its no valid pkpass file.

Maybe someone has that problem too?

My server code:

   return h
     .response(walletData)
     .type('application/vnd.apple.pkpass')
     .code(200)

My React code:

      .get(`/appleWalletCard/${user.me._id}`)
      .then((response: any) => {
        if (response) {
          const file = new Blob([response.data])
          console.log(file)
          const fileURL = URL.createObjectURL(file)
          const link = document.createElement('a')
          link.href = fileURL
          link.click()
        }
      })

Solution

  • Here is the solution: You have to set the responseType to array buffer.

    .get(`/appleWalletCard/${user.me._id}`, {
            responseType: 'arraybuffer'
          }