Home > Mobile >  display file from url with content type octet-stream inside of a html page
display file from url with content type octet-stream inside of a html page

Time:10-25

we get PDFs from Azure which have a Content-Type of application/octet-stream. I want to embed this PDF inside of a <iframe> or <object> (or anything else thats capable of doing it) HTML page.

I tried to convert the PDF to a Base64 String, but has too bad performance, because it could be that we got 50 PDFs on the same page. The PDFs itself are logos, don't ask me why they are PDFs.

Is there any other way i can try? Is it in any way possible to display in an image tag?

We are using Java in our backend, so i could change some settings of the file before delivering it to the frontend.

EDIT

as suggested, i tried to set the content-type of the files inside the Azure Container to application/pdf like the following:

for (BlobItem blobItem : container.listBlobs()) {
    if (blobItem.getName().split("\\.")[1].equals("pdf")) {
        BlobItemProperties props = blobItem.getProperties();
        props.setContentType("application/pdf");
        blobItem.setProperties(props);
    }
}

However, the content-type inside of the Azure Container is not being changed. What do i miss?

CodePudding user response:

The best answer to that problem is to just update the files inside the Azure Container to have a content-type of application/pdf.

In Java i managed to do this like this:

for (BlobItem blobItem : container.listBlobs()) {
        if (blobItem.getName().split("\\.")[1].equals("pdf")) {
            BlobClient blobClient = container.getBlobClient(blobItem.getName());
            BlobHttpHeaders headers = new BlobHttpHeaders();
            headers.setContentType("application/pdf");
            blobClient.setHttpHeaders(headers);
            LOGGER.info("Updated content-type to application pdf for logo: {}", blobItem.getName());
        }
    }
  • Related