Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:18:54+00:00 2026-06-17T08:18:54+00:00

Cut to the chase… I’d like to take a local image file, use javascript

  • 0

Cut to the chase… I’d like to take a local image file, use javascript to create a dataurl value from that image. I’m not totally sure how to go about doing that. I have looked at a bunch of code examples and i’m not real sure on what exactly they are doing with the canvas stuff. Also can I even hope to access local files for this? I am willing to bet that, that would be a security risk and javascript wouldn’t be able to reach out past it’s sandbox.

Essentially, with REAL paraphrased JS, this is what i’m looking to do…

var imgTest = "/tmp/prev/localimage.jpeg";
var imgTest = imgTest.toDataUrl;
document.write(imgTest);

The end result hopefully being a dataurl string printed to the webpage, “data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE…”

Does this make sense? I just want that dataurl information in a variable.

Thanks so much for your great advice StackOverflow!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:18:55+00:00Added an answer on June 17, 2026 at 8:18 am

    “The toDataURL() method requires that any images drawn onto the canvas are hosted on a web server with the same domain as the code executing it. If this condition is not met, a SECURITY_ERR exception is thrown.” Source

    To me, this sounds like it will not work with local files and is used to generate encoded image data from content drawn on an HTML5 canvas.

    Looking at the Mozilla documentation confirms that toDataURL() is a function specifically for the canvas object, not an image object.

    If I understand correctly, you may be able to draw the image on a canvas of the same dimensions and then use the toDataURL() method to generate your encoded data. This, of course, assuming the image file resides in the same location as the JavaScript code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to cut an image for small pieces from database. My code
Trying to cut a Line, read from a file, into a list of strings.
How to cut part from this string... abb.c.d+de.ee+f.xxx+qaa.+.,,s, ... where i know position by
I am trying to cut over an existing WebForms app to use Routing, and
The following is a cut from my registration page. How can i make all
How to cut off known substring from the string in sh? For example, I
I'll cut to the chase to save you all some boredom of surplus reading:
I'll cut right to the chase. Right now I am developing a web based
I'll cut to the chase. I have two questions about switch that are simple,
A cut down version of my code sort of looks like this: string=test test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.