// Try to check your value for "null" and "undefined" first, before use it // Example: if(byteData) byteData = byteData.split(';')[1].replace("base64,", "");