Pixelairport's avatar

Temporary URL (Workaround) ... reload in SPA when it is not valid anymore

I have a vue app and files of the users are stored in S3. When they load the SPA, I make an API call to get all files with all temporaryurls (2 minutes lifetime). What if the user navigates after 2 minutes to the images... the images are not there anymore. What is the right way to do it:

  1. Also have a lifetime in response and reload if they are not valid anymore?
  2. Just make the lifetime up to 3 days or something like that?

maybe another solution?

0 likes
2 replies
martinbean's avatar
Level 80

@pixelairport I don't really know what you’re trying to achieve. If you’re displaying the images in the browser then you only need a lifetime long enough to get the URL and put it in an <img> element, which 2 minutes is sufficient for.

If you’re displaying the image filenames in a list and want a user to be able to click them to view the actual image, then generate the temporary URL only when they click the image. You can have a route in your application that takes the path as a parameter and returns an appropriate URL if the user is authorised to view that file:

Route::get('open/{path}', 'FileRedirectController');
class FileRedirectController extends Controller
{
    public function __invoke($path)
    {
        // Authorise user can access file at path

        return Storage::temporaryUrl($path, '+5 minutes');
    }
}
1 like
Pixelairport's avatar

The file list is loaded into vue at the beginning. Sometimes the user need some images right from the start. The user needs different files in different areas. I wanted to avoid to do a request everytime user changes the area. But ok maybe i have to do it this way and load images, when user needs them and then load the images again everytime user visits the url in SPA again.

PS: It is like a web page builder with different pages and I loaded all images at the beginning.

Please or to participate in this conversation.