Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post method is not able to properly download a Stream #356

Open
Irene350 opened this issue Sep 19, 2024 · 1 comment
Open

Post method is not able to properly download a Stream #356

Irene350 opened this issue Sep 19, 2024 · 1 comment

Comments

@Irene350
Copy link

Hi I'm not sure if this is an issue or I'm doing something wrong.
I'm trying to call an external API to download a PDF file that I will later encode into a base64 string.

I used .post from RESTDataSource class.
But the string I receive is not correct.

I tried the same using axios and everything is perfectly working.
This is the working code:

const response = await axios({
        method: "post",
        url: `${this.baseURL}/storefrontapi/hot/orders/${orderId}/export/pdf`,
        headers: {
          Accept: "application/json-patch+json, */*",
          authorization: `Bearer ${this.context.token}`,
          "Content-Type": "application/pdf",
        },
        responseType: "arraybuffer", // Ensure binary data is handled correctly
      })

This is the not working call using RESTDataSource method.

const response = await this.post(`storefrontapi/hot/orders/${orderId}/export/pdf`, {
        headers: {
          Accept: "application/json-patch+json, */*",
          authorization: `Bearer ${this.context.token}`,
          "Content-Type": "application/pdf",
        },
      })

I can't use responseType here because is not supported, I didn't find any way to pass it to the post function.

@sailesh97
Copy link

I guess the 2nd arg in this.post is not correct. Check syntax how to pass headers in RESTDataSource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants