JavaScript Is there a way to import an image file using fabric.js?

I am currently working on importing png or svg files onto a canvas using the fabric.js library and an input file button. The code below works only if the image is in the root folder. I know that I don't have access to the file path, so I tried creating an element out of the file. There is no error in the console but nothing shows in the canvas. Is there a way to do make the importation work or is there a different library that could help me do this? I am using fabric.js in order to be able to scale and move the images within the canvas.

function upload(){
    var canvas = new fabric.Canvas('canvas');
    var file = document.getElementById('file').files[0].name;
    fabric.Image.fromURL(file, function(img) {
        canvas.add(img);
    })
}
Answer:1

Using the node.js console, I get the following unexpected results: > 2 + "3" "23" > 2 * "3" 6 Why does the first example favor string concatenation and integer multiplication in the second ...

Using the node.js console, I get the following unexpected results: > 2 + "3" "23" > 2 * "3" 6 Why does the first example favor string concatenation and integer multiplication in the second ...

  1. unexpected results in javascript

I know this has been discussed in other threads, but I've very new to coding websites in general, and when I try to use the solutions others have come up with, they just don't seem to work. And I ...

I know this has been discussed in other threads, but I've very new to coding websites in general, and when I try to use the solutions others have come up with, they just don't seem to work. And I ...

  1. twitter bootstrap close modal

I want users to be able to take a picture programmatically of a design they have made on my site . The design would be in a div that is a panorama that extends off both left/right edge of the screen. ...

I want users to be able to take a picture programmatically of a design they have made on my site . The design would be in a div that is a panorama that extends off both left/right edge of the screen. ...

  1. screenshot is possible with htmlunitdriver
  2. screenshot if possible
  3. screenshot not possible

The new JS enabled page of http://mail.google.com is making trouble to get ID of password input field. However, I've navigated from email ID page with its ID - identifierID . Help me to get ID of ...

The new JS enabled page of http://mail.google.com is making trouble to get ID of password input field. However, I've navigated from email ID page with its ID - identifierID . Help me to get ID of ...

  1. password input field html
  2. password input field in react native
  3. password input field unity
  4. password input field in angular material
  5. password input field
  6. password input field css
  7. password input field django
  8. password input field validation
  9. password input field type html
  10. password input field type
  11. show password input field bootstrap
  12. show password input field
  13. angular password input field
  14. qt password input field
  15. show password input field jquery
  16. php password input field
  17. bootstrap password input field
  18. react password input field
  19. yii2 password input field
  20. hide password input field