Uploading and Displaying User Avatars

In this lesson, we'll learn how to validate and upload avatar images into our project's storage. We'll then learn how we can easily display images we have contained within our app's storage

Published
Jun 01
Duration
15m 29s

Developer, dog lover, and burrito eater. Currently teaching AdonisJS, a fully featured NodeJS framework, and running Adocasts where I post new lessons weekly. Professionally, I work with JavaScript, .Net C#, and SQL Server.

Adocasts

Burlington, KY

🕰️ Chapters
00:00 - Adding Avatar File Input Field
01:06 - Adding AvatarUrl Hidden Field
01:40 - Validating Avatar and AvatarUrl Fields
03:05 - MultipartFile Options
03:52 - Moving the Uploaded Image to Storage
05:25 - Storing the Image's Storage Path
06:03 - Removing A User's Avatar
06:20 - Enctype Multipart Form Data
07:30 - Downloading Stored Avatar Images
10:10 - Displaying Stored Avatar Images
10:53 - Allowing Users to Remove Their Avatar
12:36 - Deleting the User's Avatar Image on Remove
13:40 - Testing Our Upload & Remove Flow
14:10 - A Few Things To Notes

Join The Discussion! (5 Comments)

Please sign in or sign up for free to join in on the dicussion.

  1. Commented 4 months ago

    Can you please tell me how to upload image in s3 in adonis js 6 please i am unable to do this because v5 methods are not working Thanks

    2

    Please sign in or sign up for free to reply

    1. Commented 4 months ago

      Answered on YouTube, but will answer here as well:

      Hey there! The updated version of Drive is coming soon to AdonisJS 6, and it's called FlyDrive! As of now, the package is ready, they're just working to add the tight integration directly into AdonisJS 6. So, you can configure it and use it in AdonisJS 6 now, then swap to the direct implementation once it's released if you wish. Alternatively, you can always directly use the S3 SDK provided directly from Amazon. You can find the documentation for it here: https://flydrive.dev/docs/introduction

      We do plan on doing lessons on FlyDrive in the future!

      0

      Please sign in or sign up for free to reply

  2. Commented 2 months ago

    Thanks Tom for the tutorial!
    I am trying to implement upload action that will work in localhost with file-system, and in production with s3. Can you please tell how to do it with minimum code? I guess that using DRIVE_DISK in .env file should be enough, but I do not manage to have the same code working for both s3 and local file system.

    1

    Please sign in or sign up for free to reply

    1. Commented 2 months ago

      Thanks for watching, Guy!

      For that, I'd recommend using Drive (FlyDrive). Its goal is to provide a unified API regardless if you're working with the local disk, S3, GCS, etc. We, unfortunately, don't have any lessons on FlyDrive of yet but the documentation is pretty great! With it, the only thing you should need to change between local and production is that DRIVE_DISK environment variable and the APIs between local and S3 will be the same (bar any advanced situations).

      Drive is a wrapper around FlyDrive specifically integrating FlyDrive with AdonisJS. Both, written and maintained by the AdonisJS core team.

      0

      Please sign in or sign up for free to reply

      1. Commented 2 months ago

        Thanks. I tried it but got problems with relative and absolute path, and could not manage to have the same code working with both fs and s3 depending on the environment argument DRIVE_DISK. I understand that basically the same code should work for both, I will give it another try :-)

        0

        Please sign in or sign up for free to reply