Have the following domain class:
class Topic {
byte[] image
}
It’s controller:
class TopicController {
def uploadImage () {
println params
if(params.image && params.id && params.image.length != 0){
def topic = Topic.get(params.id)
topic.image = params.image
}
}
}
And ajax request:
function postImage(){
var topicId = $('#topic-id').attr('value');
var imageData = context.getImageData(0,0,canvas.width, canvas.height);
$.post("../uploadImage", {'id': topicId,'image': imageData.data});
}
It’s not enabled to send image data (imageData.data). What’s right way to do it?
When i remove all references to image, that’s okay, but not what i want. In another case neither id nor image are detected on controller’s side (params map).
UPDATE: The problem was solved in such way. Controller method:
def uploadImage() {
//println params
if(params.image && params.id){
def topic = Topic.get(params.id)
topic.image = Base64.decode(params.image)
}
}
JS function:
function postImage(){
var topicId = $('#topic-id').attr('value');
var image = canvas.toDataURL("image/png");
image = image.replace('data:image/png;base64,', '');
$.post("../uploadImage", {'id': topicId,'image': image});
}
But i continue to get next messages on the browser side:
Failed to load resource: the server responded with a status of 404 (Not Found)
POST ../uploadImage 404 (Not Found)
What should i do to fix it?
To fix your remaining issue, try rendering some content at the end of your
uploadImagemethod:If you don’t do something that causes the response to be committed (e.g.
render()orredirect()), Grails will try to render a view with the same name as the action (in your case,uploadImage.gsp).