Как загрузить PDF, переданный Django, в Angular?

В Django у меня есть функция, которая возвращает мне pdf

def get(self, request):
        with open(filepath, 'rb') as f:
            pdf = f.read()

        return HttpResponse(pdf, content_type='application/pdf')

В Angular у меня есть

this.http.get(apiUrl, { responseType: 'arraybuffer' }).subscribe(
      response => {
        // Create a blob object that represents the PDF file
        var blob = new Blob([response], { type: 'application/pdf' });

        // Create an object URL that points to the blob
        var objectURL = URL.createObjectURL(blob);

        // Use the object URL as the src attribute for an <iframe> element
        // to display the PDF file
        document.getElementById('iframe').src = objectURL;
      },
      error => {
        console.log(error)
      }
    );

В <iframe> я получаю "Unable to upload PDF document"

Что я делаю не так?

Вернуться на верх