admin管理员组文章数量:1387356
If I create a dynamic bitmap on the clientside via javascript, how can I submit this via POST or GET ( and then parse out values from the bitmap on the serverside? NodeJS, PHP etc )
From Making Images Byte-by-Byte in Javascript
var src = 'data:image/bmp;base64,' + myBase64EncodedData;
If I create a dynamic bitmap on the clientside via javascript, how can I submit this via POST or GET ( and then parse out values from the bitmap on the serverside? NodeJS, PHP etc )
From Making Images Byte-by-Byte in Javascript
var src = 'data:image/bmp;base64,' + myBase64EncodedData;
-
why not use ajax to post values to server and retrieve from server side with
request.params['image']
in whatever language you use? – Srinivas Reddy Thatiparthy Commented Oct 25, 2012 at 20:48
2 Answers
Reset to default 4Just upload the base 64 data. Parse it on the server side form there any way you like.
HTML:
<form id="uploadImage" method="POST">
<input type="hidden" name="imageData64" id="imageData64"/>
<input type="submit" value="upload"/>
<form>
JS:
document.getElementById('uploadImage').onsubmit = function() {
document.getElementById('imageData64').value = myBase64EncodedData;
};
Or you could do the same with an ajax request.
You probably don't want to use GET though. Partly because it's not appropriate, you aren't retrieving anything form the server. But more because GET puts some limits on URL length, so your image data may not fit. POST has no such limit since the request can have a body, unlike GET.
You can use post like this..
HTML
<img src="whatever.jpg" id="myimage" />
<div id="button" data-role="button">Click on button</div>
JS
$(function() {
$("#button").click(function() {
postImageData();
});
});
function postImageData(){
var img = document.getElementById('myimage')
var myBase64EncodedData = getBase64Image(img);
$.ajax({
type: 'POST',
url: 'http://same_domain_url./',
data: {
'imagedata': myBase64EncodedData
},
success: function(msg){
console.log('posted' + msg);
}
});
}
php
$imagedata=$_POST['imagedata'];
For getBase64Image function refer to this SO question Get image data in JavaScript?
本文标签: How do you submit a Javascript generated bitmap image via POSTStack Overflow
版权声明:本文标题:How do you submit a Javascript generated bitmap image via POST? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744522283a2610525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论