Application/pdf response from API call interpreted as text/xml

Izabela Rosińska (260462) 0 Reputation points
2023-11-30T14:13:00.0366667+00:00

Hi!

I have backend Spring Boot 2 app deployed as Azure Web App. It connects with Angular frontend deployed as Azure Static Web App. My backend generates pdf file which is sent as byte[] with 'application/pdf' header. Frontend App gets reponse as Blob and displays it.

It worked on my local environment and worked also for some time on Azure. Unoftunately it stopped working on Azure (still works locally). It's a group project and many changes were made in the whole code (but not in the given functionality). I tried to fix this issue for four days and the only trail I found was addition of staticwebapp.config.json file.

I need to make this work back on Azure, thanks for all help!

Current errorBrak opisu.

Backend (Azure Web App)User's image

Frontend (Azure Static Web App)Brak opisu.

Brak opisu.

Brak opisu.

Brak opisu.

Thanks for all help!

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,192 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,173 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anand Prakash Yadav 7,855 Reputation points Microsoft External Staff
    2023-12-04T12:14:39.9766667+00:00

    Hi Izabela Rosińska (260462) 

    Thank you for posting your query here!

    Based on the information you provided, it seems that the issue is with the backend Spring Boot 2 app deployed as Azure Web App. The error message you provided indicates that there is an internal server error (500) when the frontend app tries to get the pdf file from the backend app.

    One possible reason for this issue could be that the backend app is not able to generate the pdf file correctly. You mentioned that the backend app generates the pdf file and sends it as a byte array with 'application/pdf' header. However, it is not clear from the code you provided how the byte array is being sent to the frontend app.

    Another possible reason for this issue could be related to the staticwebapp.config.json file. You mentioned that you added this file and it worked for some time on Azure. However, it stopped working later. It is possible that the changes made to this file are causing the issue.

    If possible, please try rolling back the changes to a known working state and then gradually reintroduce them while checking for the issue.

    To troubleshoot this issue, you can try the following steps:

    1. Check the backend app logs to see if there are any errors or exceptions being thrown when the pdf file is being generated. You can also try to generate the pdf file locally and see if it works correctly.

    2. Check the network traffic between the frontend and backend apps to see if the request and response are being sent correctly.

    3. Check the staticwebapp.config.json file to see if there are any errors or typos in the configuration. You can also try to remove this file and see if it works correctly without it.

    4. You can also try to redeploy the Web App or Static Web App to see if it resolves the issue.

    Please let us know if the issue persists. I’m happy to assist you further.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.