"Looking to display an image object retrieved from AWS S3 using a signed URL in Vue.js? Here's how you

<div v-for="(data, key) in imgURL" :key="key">
 <img :src= "getLink(data)" />
</div>

imgURL here is an array that contains file names.

  methods: {
     async getLink(url){
      let response = await PostsService.downloadURL({
        imgURL : url
      })
      //return response.data
      let imgdata = await axios.get(response.data)
      console.log(imgdata.data)
      return imgdata.data
     }
  }

The base64 image is printed in the console like this:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwAAAAHkCAIAAAAGqd9kAAAAA3NCSVQICAjb4U/gAAAAGXRFWHRTb2Z0d2FyZQBnbm9tZS1zY3JlZW5zaG907wO/PgAAIABJREFUeJ.....

However, the image does not load on the page.

I have tried using a direct URL generated by the server but it doesn't work because I am only storing part of the file name and using it to generate the complete URL. The signedURL generated in the code above is "response.data".

I am uploading images using FileReader and Axios with the signedURL.

I need help identifying where the issue lies.

Answer №1

Instead of using base64 encoded data to display an image, consider using a signed URL for better performance. I used to download image data like you, but then realized that using a signed URL as the image source is more efficient. Generating a signed URL is synchronous, making it easier to manage in your code.

So, instead of the following:

<div v-for="(data, key) in imgURL" :key="key">
  <img :src= "getLink(data)" />
</div>

You can do this:

<div v-for="(data, key) in imgURL" :key="key">
  <img :src="data" />  // Utilize the 'data' value here
</div>

Answer №2

To load a presigned image URL in Vue3 and Vuetify3, follow the steps below:

Simply use the lazy-src, eager, and src props as shown in the example below:

 <VAvatar rounded size="120">
            <VImg
              cover
              :src="release.artwork_image"
              :lazy-src="release.artwork_image"
              alt="loading"
              eager
            />
          </VAvatar>

Alternatively, to add a custom loader you can utilize the following 2 approaches:

<VAvatar rounded size="120">
           <img
              class="v-img__img v-img__img--cover"
              width="100"
              height="100"
              :src="release.artwork_image"
              @load="onImageLoad"
            />
            <VProgressCircular
              v-if="imgloader"
              :size="30"
              width="3"
              color="primary"
              indeterminate
            /> 
          </VAvatar>

Your @load event will trigger as follows:

<script setup> 
  const imgloader = ref(true);
  const onImageLoad = () => {
   imgloader.value = false;
 };

We hope this guide proves beneficial for you! Happy coding!

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

Adjust hover effects based on true conditions

Currently working on a web app using HTML, CSS, JavaScript, and AngularJS. Progress so far includes a clickable box that triggers a javascript function to display more boxes upon click using ng-click. <div ng-click="!(clickEnabled)||myFunction(app)" cl ...

Unable to save object in JavaScript memory

Currently, I am in the process of implementing a Stack in JavaScript using a LinkedList. However, I encountered an issue when trying to instantiate a Node class. When attempting to create a variable let newNode = new Node(x), I am receiving undefined. I a ...

Utilize text alignment effectively by considering language direction - left-to-right for English and right-to-left for Arabic

I am managing a community website and I am looking to customize the text direction based on the language of the posts. For English posts, I want the direction to be LTR with text-align: left) For Arabic posts, I want the direction to be RTL with text-ali ...

Customizing the appearance of charts in AngularJS using the Chart.js

I just started experimenting with AngularJS and recently created a horizontal bar chart using Chart.js and HTML. My next step is to make the chart dynamically appear on the page with the help of AngularJS. Can someone please provide some guidance on how I ...

"Troubleshooting the issue with the @click event failing to update the data

Working in Vue.js, my v-for loop is set up to go through a list and generate buttons. Each button has a click event that should change the value of upUrl to its index: <div class="mt-3" v-for="(buttonPic, index) in buttonPics" ...

Confirming the browser exit on IE9

While searching on stackoverflow.com, I noticed an abundance of inquiries about a specific issue, but unfortunately, there doesn't seem to be a clear answer available. Apologies if this adds to the duplicate questions. In my Ajax-based web applicatio ...

Encountered an issue with launching Chrome in Puppeteer for Node.js

My code was uploaded to EC2 AWS, but unfortunately it is not working properly after the upload. Interestingly, it runs correctly on localhost. Despite trying various solutions, I am still facing this issue. Any suggestions on the correct approach to resolv ...

Discover the simple steps to include row numbers or serial numbers in an angular2 datagrid

Currently, I am utilizing angular2 -datatable. Unfortunately, I am facing an issue where the correct row numbers are not being displayed in their corresponding rows. Whenever a user moves to the next page using the paginator, the datatable starts countin ...

Utilizing classes as types in TypeScript

Why is it possible to use a class as a type in TypeScript, like word: Word in the provided code snippet? class Dict { private words: Words = {}; // I am curious about this specific line add(word: Word) { if (!this.words[word.term]) { this.wor ...

How can I properly integrate the datatables.net plugin with a Vue application using Webpack?

I am currently working on a Vue Webpack project that requires the use of DataTables as a plugin. However, integrating jQuery, which is needed for DataTables, directly into my Vue component has proven to be a challenge. Here's how I'm currently h ...

Trigger a JQuery popup by toggling a class with a button

Hey there! I have a modal popup that utilizes an active class. When this class is present, the modal appears, and when it is removed, the modal disappears. I am trying to create a button that, when pressed, will show the modal, and a close button inside th ...

How to add multiple entries using Node.js and Tedious

I am currently working with an array of customer objects that I need to insert into a SQL database. These customer objects are retrieved from the request data. For this task, I am utilizing Tedious for handling the request and Tedious Connectionpool to ma ...

VUEX doesn't recognize a mutation that has been defined

I recently started using VUEX and everything was going smoothly until I introduced a new mutation called "shipping". Now, every time I try to commit it, I get an error message saying: unknown mutation type: shipping. It's puzzling because all my previ ...

Switch out "FOR" in order to sum up every value within an array

Utilizing Javascript, I have an array defined as follows: counts: [ { id: 1, value: 0 }, { id: 2, value: 10 }, { id: 3, value: 5 }, { id: 4, value: 3 } ] I aim to calculate a variable named total that holds the sum of all valu ...

Eliminate the CSS triggered by a mouse click

Having some difficulty toggling the switch to change the background color. Struggling with removing the applied CSS and getting it to toggle between two different colored backgrounds. Code Sample: <!Doctype html> <html lang="en"> <head> ...

A guide on updating URLs that are not enclosed within an anchor tag using JavaScript

In my current scenario, I am dealing with text that includes URL links presented in two different formats. www.stackoverflow.com <a href="http://www.stackoverflow.com">Stack over flow</a> My objective is to create a straightforward function ...

Ability to access functions from required modules that are defined within the calling module

Is there a way to call a function within a required module that is defined in the main program without copying or creating separate files? Main.js: var http = require('http'); var aFunc = function() {return 1;} var bFunc = require('./bFunc ...

reinitializing an array duplicate within an angular function following the use of .splice()

My goal is to create a dropdown menu in Angular that automatically removes the current page from the list when navigating to another view. I want the menu to reset and remove the now-current view every time a new view is loaded. This is the array of objec ...

add text nodes with unnecessary quotation marks around my selection list

Looking to incorporate a select list into my website using a button. I must utilize nodes for access within the DOM to retrieve its value later, so innerHTML isn't an option. Experiencing difficulty as createTextNode seems to encase my list in quota ...

Why is the complete object not being saved in the mongoose subdocument array?

I encountered a problem with my two nested schemas, where one is inside the other as an array. Even though I tried to push into the array and save the subdocument, it didn't save correctly. The saved object only includes its _id without any other fiel ...