简体   繁体   English

Podio Javascript SDK:客户端无法显示podio中的图像

[英]Podio Javascript SDK: Client Restricted from displaying Image from podio

I'm currently using Podio JS SDK to connect to the podio REST API. 我目前正在使用Podio JS SDK连接到podio REST API。 I have setup a login screen to capture username and password using the username and password authentication flow. 我已经设置了一个登录屏幕,以使用用户名和密码验证流程捕获用户名和密码

I can make request and get information that I need. 我可以提出请求并获取所需的信息。 In one of my request i receive an image url. 在我的要求之一中,我收到了图片网址。 I then place the img url into an image tag like so, 然后,将img网址放入这样的图片标签中,

<img src="img.url"/> 

The problem is that my client can't not view the image. 问题是我的客户无法查看图像。 I looked here at Working with files in order to find an answer. 我在这里查看了“使用文件”以找到答案。

The problem is that the image can only be viewed in the client by a user who is currently logged in, but I've already authenticated. 问题是该图像只能由当前登录的用户在客户端中查看,但是我已经通过身份验证。

Am I missing something? 我想念什么吗? How can I show the image, being that I've already logged in with the username and password, I'm storing the access_token, refresh_token, etc. in local storage and can make all other necessary calls. 如何显示图像,因为我已经使用用户名和密码登录,所以我将access_token,refresh_token等存储在本地存储中,并且可以进行所有其他必要的调用。

Try sending the images via headers. 尝试通过标题发送图像。 This used to work, though it is a quite clunky solution. 尽管它是一个很笨拙的解决方案,但它曾经可以工作。 Might be deprecated with the new PodioAPI. 可能不推荐使用新的PodioAPI。

First set up your function. 首先设置您的功能。

function showImage($item, $index, $id, $style = '', $class='', $alt='',$imgtitle='') {

foreach($item->fields as $field) {

    if($field->field_id== $id) {
        $picture_id = $field->values[$index]['value']['file_id'];
        echo "<img style='$style' class='$class' src='getImage.php?id=$picture_id' alt='$alt' title='$imgtitle' />";
        global $picture_id;
    }
}
}

This would be your getimage.php. 这将是您的getimage.php。 You could also setup a PDF like that. 您也可以像这样设置PDF。

$img_id = $_GET['id'];

$cache = new cache(
        ...
        );

$file_id = "image{$img_id}";
if(!$cache->has($file_id)) {
    $file = $cache->set($file_id, PodioFile::get($img_id));
} else {
    $file = $cache->get($file_id);
}

$picture_id = "image_cache_{$img_id}";
if(!$cache->has($picture_id)) {
    $image = $cache->set($picture_id, Podio::get($file->link, array(), array('file_download' => true))->body);
} else {
    $image = $cache->get($picture_id);
}

header('Content-Type: image/png');
echo $image;

hope it helps. 希望能帮助到你。

Though you have an access token and can access all of your podio data by using the username and password authentication , Podio's authentication is cookie based, so if your client doesn't authenticate through the podio web app's login screen your client won't be able to read images directly from the web app. 尽管您具有访问令牌,并且可以使用用户名和密码身份验证来访问所有podio数据,但Podio的身份验证是基于Cookie的,因此,如果您的客户端无法通过podio Web应用的登录屏幕进行身份验证,则您的客户端将无法直接从网络应用读取图像。 Your access will be blocked. 您的访问将被阻止。

Solution

If you do not authenticate through the client, but have access to the api, you can download the raw image data from here: https://api.podio.com/file/{{imgId}}/raw . 如果您不通过客户端进行身份验证,但可以访问api,则可以从以下位置下载原始图像数据: https://api.podio.com/file/{{imgId}}/raw ://api.podio.com/file/{{imgId}}/raw。 Once you get the raw image data you can encode the data into base64 format and you use a Data URI as the src of your <img> tag in your client if it is a web client. 一旦获得原始图像数据,就可以将数据编码为base64格式,并且如果它是Web客户端,则可以在客户端中将Data URI用作<img>标签的src

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM