Search code examples
phphtmldreamfactory

How to display images in files folder from dreamfactory using php


I have uploaded images files in folder of Dreamfactory

<img src="https://motodev.spotya.online/api/v2/files/Posts/posts_1508937621_Tulips.jpg">

Error Displayed,

{"error":{"code":400,"context":null,"message":"No session token (JWT) or API Key detected in request.."}


Solution

  • It looks like your files endpoint in dreamfactory is secured. You need to provide API key or JWT token to access the files inside this directory. Another way is to add guest access to your files endpoint, as described here.

    You need to generate url like https://example.org/api/v2/files/image.jpg?api_key=<your api key>. For example:

    <?php
    
    // your guest API key
    $apiKey = 'your api key should be here';
    // your file URL
    $baseUrl = 'https://example.org/api/v2/files/image.jpg';
    // resulted URL
    $finalUrl = $baseUrl . http_build_query(['api_key' => $apiKey]);
    
    ?>
    
    <img src="<?= $finalUrl ?>">