var imgurl = data; if (imgurl.indexOf("base64") != -1) { imgurl = data; } else if (imgurl.indexOf("data:image/jpeg;base64") == -1) { imgurl = "data:image/jpeg;base64,"+data; } else if (imgurl.indexOf("data:image/png;base64") == -1) { imgurl = "data:image/png;base64," + data; } else if (imgurl.indexOf("data:image/gif;base64") == -1) { imgurl = "data:image/gif;base64," + data; }