Figdam


👋,

You probably know that the team at Edgar Allan is behind Slater. But did you know that we work on other products in between our client work? You use Slater. You may have heard about Wes. And you probably don't know about our latest product, Figdam.

Do you know what a DAM is? a Digital Asset Manager? We are building one. Figdam helps users manage all of their images in one place, in Figma. If an image needs to be updated, swap it out in Figma, and it will be updated across the web. Figdam also supports image manipulation and analytics. It can even generate a PDF from a series of images or Figma frames.

Demo coming next week!

Javascript 101: JS & the File API

Let's continue our focus on images and discuss the File API. We can write code to preview the image before the user uploads it.

Ok, The File API is a set of APIs that allows web applications to work with file objects in the browser. It provides a way to handle file upload operations and access the contents of selected files. The File API consists of the following main interfaces and methods:

  1. File object: Represents a file that has been selected by the user or obtained from other sources like drag and drop operations or the <input type="file"> element.
  2. FileList object: A list of File objects, usually obtained from a file input element or a drag and drop event.
  3. FileReader object: Allows you to read the contents of a File object asynchronously. It provides methods like readAsText(), readAsDataURL(), readAsArrayBuffer(), and readAsBinaryString() to access the file content in various formats.
  4. Blob object: A raw data type that represents a binary large object (BLOB). It can be used to create File objects or handle binary data.

Here's an example of how you can work with the File API to display an image before file upload:

<!-- HTML -->
<input type="file" id="fileInput" accept="image/*">
<div id="imageContainer"></div>

// JavaScript
const fileInput = document.getElementById('fileInput');
const imageContainer = document.getElementById('imageContainer');

fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];

if (file && file.type.startsWith('image/')) {
const reader = new FileReader();

reader.onload = () => {
const img = new Image();
img.src = reader.result;
img.onload = () => {
imageContainer.innerHTML = '';
imageContainer.appendChild(img);
};
};

reader.readAsDataURL(file);
}
});

In this example:

  1. We add an accept="image/*" attribute to the file input element to allow only image files to be selected.
  2. We create a <div> element with an id imageContainer where we'll display the image.
  3. Inside the change event listener, we first check if a file has been selected and if it's an image file.
  4. We create a new FileReader instance and set up an onload event listener.
  5. Inside the onload event listener, we create a new Image object and set its src to the result of the FileReader (which is a data URL representing the image data).
  6. We set up another onload event listener for the Image object.
  7. Inside this second onload event listener, we clear the contents of the imageContainer div and append the Image element to it, displaying the image.

This code will display the image on the webpage without any manipulation. If you want to perform any image manipulation, you can add that logic inside the second onload event listener before appending the Image element to the imageContainer.

Note that the readAsDataURL() method is used here because it converts the image file into a data URL, which can be directly set as the src of an Image object. This approach works well for displaying images.

Your projects, supported by Slater

Dennis Snellenberg created this GSAP digital experience. Amazing! Go check it out at str8fire.io.

Are you working on something worth sharing? Please share!

Happy coding!

🤙 the Slater Team

If Slater helps you create better websites, please support the team behind it.

Welcome To Slater!

Slater resources, updates and community activity

Read more from Welcome To Slater!
video preview

How has your Webflow Conf 2024 experience been? At Edgar Allan, we are especially excited about Webflow Analyze and Optimize and how we can leverage it for our clients and with Wes. However, at Slater, we are most excited about the GSAP acquisition. We’ve been thinking about how we can better support you as you integrate GSAP and Webflow. Let’s explore how you can use Slater with GSAP: Slater Sessions - GSAP + Webflow via Chat with Witt Learn GSAP for Webflow with Aron Korenblit and Cassie...

photo

Do you get confused when undoing (cmd + z) in Slater? We auto-format your code on save. The auto-formatting updates your code, and those updates get pushed into the undo stack. You can now improve your workflow by formatting the code when you choose—not just on save. To gain more control over when your code formats: Turn off auto-format code in the Code Editor Settings Use cmd + shift + f to format your code We added a handful of other improvements: Console logs and debuggers are now...

video preview

Last week, we announced that CSS updates were on the way—and now they're here! You can now generate CSS files just as quickly and easily as JS files. In the video below, we give a quick demo of the new functionality. If you have a Smart Script loaded in your project, you can instantly add CSS. In the demo, we also show how to add CSS in the Webflow designer. Give it a try and let us know what you're building! Community Library 🖍️ Text Highlight ColorCSS code for custom text selection. 🅰...