Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

php - Unreadable content is returned when trying to show Nuxeo document

There is an API which can be used to get the preview of a Nuxeo document; it is like this :

http://localhost:8080/nuxeo/site/api/v1/repo/default/id/563c04bf-897d-48e5-863e-08cebeeccb06/@blob/file:content/@preview/image

It should show an image content :

enter image description here

Now I called it inside file_get_contents and I get unreadable content :

enter image description here

<?php

$opts = [
            "http" => [
                "method" => "GET",
                "header" => array("Authorization: Basic " . base64_encode('Administrator:Administrator'),
                        "Content-type: image/jpg")
            ]
        ];
$context = stream_context_create($opts);

echo file_get_contents("http://localhost:8080/nuxeo/site/api/v1/repo/default/id/563c04bf-897d-48e5-863e-08cebeeccb06/@blob/file:content/@preview/image", false, $context);

?>

I tried using gzdecode but I get data error exception although magic_quotes_runtime is not present in the ini file.

So how to fix it ?

edit :

Even if curl-ing it then I get the same result :

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://localhost:8080/nuxeo/site/api/v1/repo/default/id/563c04bf-897d-48e5-863e-08cebeeccb06/@blob/file:content/@preview/image");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Basic ' . base64_encode('Administrator:Administrator'),
    'Content-Type: image/jpeg'
));

curl_exec($ch);

curl_close($ch);

edit 2 :

Here are the headers from the dev tool :

    Request URL: http://tester/nuxeodociframe.php
Request Method: GET
Status Code: 200 OK
Remote Address: [::1]:80
Referrer Policy: strict-origin-when-cross-origin

    **Response Headers**

    Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Date: Mon, 11 Jan 2021 13:50:53 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.39 (Win64) PHP/7.2.18
Transfer-Encoding: chunked
X-Powered-By: PHP/7.2.18

    **Request Headers**

    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: max-age=0
Connection: keep-alive
Cookie: qa_id=3976046217316149434; qa_noticed=1; RT="z=1&dm=tester&si=9brcldlzx2&ss=kjsghu2u&sl=0&tt=0"; __utma=244493312.1444286480.1610362906.1610362906.1610362906.1; __utmc=244493312; __utmz=244493312.1610362906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Host: tester
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your browser needs to know how to decipher the information it receives. In this case you must "inform" him that it is a picture. Therefore you will add:

Edit: add this line before any echo

header("content-type: image/jpeg");

If the image is not jpeg you must add a suitable header

Also remove the close tag ?>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...