"Implementing Vue.js and Firebase to handle image uploading, resizing, and storage

I am currently working on a SPA app using Vue js and firebase. My goal is to upload an image, resize it to fixed dimensions, and then upload it to firebase.

To achieve this, I have incorporated the use of the Jimp npm package for resizing the uploaded image.

Below is my implementation:

Main.js

import Jimp from 'jimp';
Window.Jimp = Jimp;

This snippet demonstrates how I handle image uploads:

    uploadImage(e) {
  if (e.target.files[0]) {
    let file = e.target.files[0];

    Jimp.read(file)
      .then(lenna => {
        return lenna
          .resize(256, 256) // resize
          .quality(60) // set JPEG quality
          .write(file.name); // save
      })
      .catch(err => {
        console.error(err);
      });
      conslole.log(lenna);
    var storageRef = fb.storage().ref("products/" + file.name);

    let uploadTask = storageRef.put(file);

    uploadTask.on(
      "state_changed",
      snapshot => {},
      error => {},
      () => {
        uploadTask.snapshot.ref.getDownloadURL().then(downloadURL => {
          this.product.images.push(downloadURL);
          console.log("File available at", downloadURL);
        });
      }
    );
  }
}

While implementing the above code, I encountered the following error message:

No matching constructor overloading was found. Please see the docs for how to call the Jimp constructor.

I would appreciate any assistance in identifying the mistake I may have made in this process.

Answer №1

Start by generating a buffer, then transfer that buffer to jimp.load():

const imageDataBuffer = new Buffer.from(data, 'base64');
const jimpImageBufferPromise = await Jimp.load(imageDataBuffer);

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

Showing components within my two-dimensional array using Javascript

I am dealing with a post function that generates a 2d array. I am looking for a way to display each individual element within it. Here is a snippet of my code: $.post("/Question/GetPollQuestionsForView/", { poll_ID: pollId }, function(result) { //$("#C ...

Is it true that eliminating white spaces can enhance a website's loading speed?

I'm curious about something. Can removing white space actually make a website load faster? For instance, take a look at the following CSS snippet - body{ overflow-wrap:break-word; word-break:break-word; word-wrap:break-word } .hidden{ display:none } . ...

Achieving successful functionality with position:relative in IE9

Having difficulty with the position: relative property in IE9. Check out this demo for reference: <div style="overflow:scroll;height:120px;"> <table id="table" width="100%"> <tr style="position:relative;background-color:#1b72a4;"> ...

I am facing difficulties retrieving the JSON object returned from the Express GET route in Angular

After setting up an express route, the following JSON is returned: [{"_id":"573da7305af4c74002790733","postcode":"nr22ry","firstlineofaddress":"20 high house avenue","tenancynumber":"12454663","role":"operative","association":"company","hash":"b6ba35492f3 ...

Having trouble with the webpage not loading correctly after implementing react-router-dom

I recently installed 'react-router-dom' and 'react' in order to implement a routing feature in my project. Despite adding 'react-router-dom' to my devDependencies within the package.json file, I am encountering issues with the ...

Javascript is not being executed on Firefox Mobile

I need help with running my local website on the Firefox mobile emulator. Although I can see the welcome page, I am unable to access the website because it requires the execution of some JavaScript. Can someone please advise me on how to enable this featur ...

What is the best way to incorporate this CodePen snippet into a Vue project?

Can anyone help me figure out how to incorporate this awesome animation from CodePen (link here: https://codepen.io/iprodev/pen/azpWBr) into a Vue project? I've tried implementing it like so: <template> <div> <canvas heigh ...

In Vue.js, leverage the power of slots to access content from deeply nested child components

Recently, I came across this example: This child component serves as the foundation for all the components that follow. <template> <div class="content-box"> <div class="boxtitlecontainer titleColor"> <slot name="title"> ...

How to create a thumbnail hover effect with CSS3 and javascript, overcoming the z-axis issue

Currently, I am working on creating a set of thumbnails that enlarge when hovered over. The initial setup achieves the zoom effect using CSS3 transform:scale and ease-in-out. However, the issue is that the enlarged images overlap each other due to sharing ...

The node application route appears to be malfunctioning

Recently delving into the world of node JS, I encountered an issue while working on my application with the following 3 files. http.createServer(app).listen(**app.get('port')**, function(){ The error message reads 'undefined is not a func ...

Enhance a collection of data with Rails and Ajax

Imagine we have multiple lists of items. <ul data-id="2"> <li> <span>Item name</span> </li> <li> <span>Item name</span> </li> <li> <span>Item nam ...

Use two separate AJAX requests to open and close the modal dialog

I am experiencing an issue with my subscription form that uses modal windows. After closing the window and trying to subscribe again, the ajax calls are being duplicated, resulting in an error. $("#openModal").click(function() { if($("#wname").val() = ...

Tips for including an object as a prop using Vue Router

When working with Vue JS3, I have encountered an issue regarding passing props in my Vue component. Here is how I am currently doing it: <script> export default { data() { return { links: [], }; }, methods: { editLink(el) { this.$ ...

What is the best way to transform a string resembling JSON or a JS object into a valid JS object?

The specific String in question was originally part of a JavaScript object as shown below: var nameVal = "Jacob"; var favNumbersVal = "{\"firstNum\":0, \"secondNum\":1, \"thirdNum\":2}"; var aJSObject = { "name" = nameV ...

Creating a link that triggers a submit event

I am stuck with this piece of code: <form name="ProjectButtonBar_deleteProject_LF_3" action="" method="post"> <a class="buttontext" href="javascript:document.ProjectButtonBar_deleteProject_LF_3.submit()">...</a> Instead of directly subm ...

What is the best way to display a new line when printing a string as <pre> in HTML without using ` `

I receive a text file from the PHP server that has the following content: "File version: 5\n\nstart: 1410355285955(2014/09/10 11:58:05.955)\nend: 141090402750(2014/09/10 12:00:02.750)\nUEID: 301660031\nCNC: 1181 ...

After implementing AXIOS, don't forget to refresh the static content in VUE

I'm encountering some issues with Vue.js: Currently, I have a list of elements that I'm iterating through using v-for in my script. This array is retrieved from Axios (API) in the created() lifecycle hook. Additionally, I have a static variable ...

Implementing functionality to switch classes when clicking outside an element using Jquery

At first glance, the code snippet reveals a method to toggle the .main-navigation and apply a shadow overlay on the page simultaneously. However, my objective is to trigger the same action (closing the menu and removing the overlay) by clicking outside the ...

fs.writeFile never completes its operation

Currently, I am attempting to store an image from a canvas onto a disk file within an Electron application using fs. Employing async/await, when the function is executed, I observe that the file is generated but lacks data until I refresh the page. The lin ...

Change the dropdown menu text to show the selected option text once the page has been redirected

Hey there, I am looking to dynamically update the dropdown text with the selected option after a page redirect and reload of the dropdown. Check out my code below: <div class="sorting-option"> <select id="selectdropdown" class="dropdown-selec ...