/    Sign up×
Community /Pin to ProfileBookmark

Post a base64 image as an input type file

Hi
I have a nice ltlle problem I hope to fin a sulution in JS and I will be werry thankfull if you guys coud help me out. ( Allso the newborn princess Estelle of Sweden will be pleased. The application I’m working on is for her )

I have a form that will take an image submitted by the user in a common way <input type=”file” name=”uploadFile”> an present i on a wp-blog.

Now I whant the form to take a base64 encoded image crated by javascript and add it to the form insted of an image subbitted by the user. Is the possible to do in javascript

Here is some example code

[FONT=”Courier New”]<html >
<head>

<title>post drawing</title>
</head>

<body>

<form enctype=”multipart/form-data” method=”post” action=”http://wordpress.local/” id=”myform”>
<input type=”text” name=”displayName”>
<textarea name=”freetext”></textarea>
<a href=”javascript:{}” onclick=”postDrawing(); return false;” >Send</a><
</form>

<script>
function postDrawing()
{

base64Image_string = “data:image/png;base64,iVBORw0KGgo … etcetra etcetra … “;
var myform = document.getElementById(‘myform’);

/* here i whant to add the image in the var base64Image_string to the form as an input type file (<input type=”file” name=”uploadFile”>) */

myform.submit();

}

</script>

</body>
</html>[/FONT]

to post a comment
JavaScript

1 Comments(s)

×

Success!

Help @luckyhansson spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...