Acquiring images from an external source and storing them in either the $lib directory or the static folder during the

Currently, I have a Sveltekit project set up with adapter-static. The content for my pages is being pulled from Directus, and my images are hosted in S3, connected to Directus for easy access. I am also managing audio samples in a similar manner.

During build time, I am looking to import or download remote images and audio samples just like the text information needed for populating my pages. In +page.server.ts, I use load functions to fetch data from the Directus API for each page at build time. However, I am facing a challenge in finding a way to include images following a similar process. Ideally, I'd like to instruct Sveltekit within the load function to "retrieve all images and audio samples from this remote folder, then save them in either /$lib or /static directories for serving as local assets in the static site."

The main goal is to offer an intuitive workflow for content editors to manage content independently without reliance on external providers. Even if the S3 or Directus instance experiences downtime, the most recent site build should be unaffected. Currently, this works for everything except image and audio assets referenced in the markup. Therefore, it would be beneficial for the content editor to upload images to S3 via Directus triggering a site rebuild, followed by my project downloading these images for local storage during build (and not relying on client-side retrieval).

In essence, the process of handling images, regardless of their location or storage method, should remain consistent. If anyone has advice on how to address this issue, suggestions on where to begin, or npm packages that could facilitate this task, it would be greatly appreciated.

Answer №1

Have you considered creating a separate script that can be run before or after the vite build command?

{
  "scripts": {
    "build": "vite build && node download-image"
  }
}

If you are using Node.js to run the build process, you can save images into the output directory (default is /build) by utilizing the node:fs module.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

SSL/HTTPS issues impacting Server-Sent Events (SSE)

Greetings, I am currently in the process of developing a React web application that is designed to receive SSE data from an Express server working with Nginx. SERVER.JS const express = require('express'); const bodyParser = require('body-p ...

Using various conditions and operators to display or conceal HTML elements in React applications, particularly in NextJS

I am seeking ways to implement conditional logic in my React/Next.js web app to display different HTML elements. While I have managed to make it work with individual variable conditions, I am encountering difficulties when trying to show the same HTML if m ...

Validation of nested phone numbers using jQuery

I'm trying to figure out how to incorporate the jQuery validation plug-in into a multi-step form where validation occurs on each step as the user progresses. I know that typically, the validation plug-in is triggered by a submit request, but in this c ...

Exploring ways to retrieve nested values from JSON data using the Instagram API and Javascript

Trying to modify the script found at https://github.com/bigflannel/bigflannel-Instafeed in order to access Instagram photos on a website. Unfortunately, the script does not currently support displaying photo comments. I attempted to make modifications that ...

Building a secure NodeJS REST API with authentication capabilities utilizing Passport and OAuth2 with the integration of

Currently, I am in the process of developing a RESTful API using NodeJS and for authentication purposes, I have opted to utilize Passport. In order to maintain true RESTfulness, I have decided to implement token-based authentication instead of sessions. M ...

Navigating through drop-down menus using jQuery

I need help with a JavaScript script that can calculate the total number of points based on selected checkboxes and dropdown values. Currently, my script is able to iterate through checkboxes and assign 1 or 2 points based on their classes, but I'm st ...

The Arrow notations don't seem to be functioning properly in Internet Explorer

Check out my code snippet in this JSFiddle link. It's working smoothly on Chrome and Mozilla, but encountering issues on IE due to arrow notations. The problem lies within the arrow notations that are not supported on IE platform. Here is the specifi ...

Try using a distinctive error message when sending a request within a Loopback application

In the development of my Loopback 3 application, I have encountered an issue. My application is sending a post request to an external service. Model.prototype.doSomething() = async()=>{ ... let res = await request.post(that service api).sen ...

What are the steps to connect to, fetch, save, and remove files from a remote file server using Node.js?

Currently working on a project in node.js that requires saving an uploaded file from a client onto a remote file server for later retrieval. While I'm familiar with accessing and storing files on the local file system using 'fs', I am unsure ...

How can I translate these JQuery functions into vanilla JavaScript?

I am currently in the process of building a configurator using transparent images. The image configurator functions through a basic JQuery function: I have assigned each input element a data attribute called data-Image. This function identifies the data-Im ...

Getting the dimensions of an image when clicking on a link

Trying to retrieve width and height of an image from this link. <a id="CloudThumb_id_1" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: 'http://www.example.com/598441_l2.jpg'" onclick="return theFunction();" href="http ...

Experiencing difficulties while attempting to utilize Appium on Ubuntu, encountering a node.js:134 error

I installed nodejs by using the following command: sudo apt-get install -y nodejs Similarly, I installed appium with the command below: sudo npm install -g appium Despite the warning on the appium page advising against using sudo, I had to use it becau ...

Stopping the animation of scrollLeft upon user interaction can be achieved by utilizing JavaScript

Here is my current code snippet: <script> $(document).ready(function() { $('.scrolls').stop().animate({ scrollLeft : 4000 },100000, 'linear') }) </script> I am looking for a way to halt the animation once ...

Encountering an issue while attempting to replicate the Spotify app on localhost:3000. The error message "TYPEERROR: Cannot read property 'url' of undefined" is hind

As a first-time user of stackoverflow, I am unfamiliar with its rules and regulations, so I apologize in advance for any mistakes I may make. Currently, I am attempting to create a Spotify clone using React. Everything was going smoothly until I completed ...

Showing post response (XMLHttpRequest) on Chrome extension interface instead of Python console

I am currently developing a Chrome extension that sends a post request with information about the specific URL being browsed by the user to Flask (local host). A web scraping process is then carried out on this URL to determine a category based on the obta ...

Having issues with angular-file-upload failing to include the file in the request

I am currently using angular-file-upload in order to upload an image to a server that is utilizing Node and Express 4.0. However, I am encountering difficulties in accessing the file data on the server. Below is the relevant code snippet: <input type= ...

Finding alternative solutions without using the find() method when working with Angular

How can I use an equivalent to find(".class") in AngularJS? I came across this solution: //find('.classname'), assumes you already have the starting elem to search from angular.element(elem.querySelector('.classname')) I attempted to ...

CSS styling doesn't take effect until the page is reloaded due to the failure of cssText

After generating a new list item, it appears that the CSS styling is not being inherited until the page is reloaded. Even though I have added styling using cssText dynamically, it doesn't seem to be working as expected. I've attempted using cssT ...

Is the branch of ExtJS 4.1 TreeStore lazy loading extending?

I am working on implementing lazy loading of tree branches in an MVC application using extjs4.1. The branches are located on different URLs and I have faced several challenges along the way. Unfortunately, at this point, the branching functionality is not ...

Is it possible for me to utilize pure JavaScript for loading JSON data?

I am interested in dynamically creating a Google Map by loading data through AJAX. To achieve this, I am using a JSON object that mimics the structure of the GM API to construct the map and jQuery for AJAX loading. For example: "object": { "div": "ma ...