0

I have a PHP REST API has written with SLIM Framework, I have an api call which creates a docx file and force the file to be downloaded.

    $filename = 'invitation.docx';
    $templateProcessor->save($filename);
    header('Content-Description: File Transfer');
    header('Content-type: application/force-download');
    header('Content-Disposition: attachment; filename='.basename($filename));
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: '.filesize($filename));
    ob_clean();
    ob_flush();
    readfile($filename);
    exit(); 
the file is created and i can read it via the server.
but the problem is in the client side the file is corrupted

  Data.get('downloadInvitation/'+ id).then(function(results) {
        var file = new Blob([results], { type:    'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
       saveAs(file, 'invitation.docx');
       });

does anyone has an idea?

1 Answer 1

0

I had the same problem. Just add responseType: 'arraybuffer' to your get configuration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.