{"id":1377,"date":"2022-08-30T15:16:01","date_gmt":"2022-08-30T15:16:01","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/15\/upload-blob-on-server-with-ajax-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:01","modified_gmt":"2022-08-30T15:16:01","slug":"upload-blob-on-server-with-ajax-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/upload-blob-on-server-with-ajax-collection-of-common-programming-errors\/","title":{"rendered":"Upload blob on server with ajax-Collection of common programming errors"},"content":{"rendered":"<p>Can anyone tell me how I can store a blob on the server with an ajax call? I have tried many things but none of them work. And I cannot find any good information about this.<\/p>\n<p>This is where I want to send the blob<\/p>\n<pre><code>class Ajax extends CI_Controller {\n\nfunction __construct()\n{\n    parent::__construct();\n    $this-&gt;load-&gt;helper('url');\n    $this-&gt;load-&gt;helper('form_helper');\n    $this-&gt;load-&gt;library('tank_auth');\n\n}\n\npublic function saverecording()\n{\n    $status = \"\";\n    $msg = \"\";\n    $file_element_name = 'komaan';\n    if ($status != \"error\")\n    {\n          $config['upload_path'] = '..\/..\/upload\/audio\/recordings\/';\n          $config['allowed_types'] = 'wav';\n          $this-&gt;load-&gt;library('upload', $config);\n          if (!$this-&gt;upload-&gt;do_upload($file_element_name))\n          {\n             $status = 'error';\n             $msg = $this-&gt;upload-&gt;display_errors('', '');\n             echo '\n             console.log(\"this is not working\");';\n          }\n          else\n          {\n             $data = $this-&gt;upload-&gt;data();\n             echo '\n             console.log(\"this is \");';\n             \/\/$file_id = $this-&gt;files_model-&gt;insert_file($data['file_name'], $_POST['title']);\n          }\n          @unlink($_FILES[$file_element_name]);\n       }\n}\n<\/code><\/pre>\n<p><strong>NEW EDIT<\/strong>: Thanks for your patience, I&#8217;m pretty new with web development. I figured out what the problem is. As I said I get a blob file from javascript code:<\/p>\n<pre><code>recorder.exportWAV(function(blob) {\n            console.log(blob);\n            $('userfile').val(blob);\n            $.ajaxFileUpload({\n            url :  \"..\/ajax\/saverecording\/\", \n            secureuri      :false,\n            fileElementId  :'userfile',\n                dataType : blob.type,\n                data: blob,\n                success: function(data, status) {\n                    if(data.status != 'error')\n                        alert(\"hoera!\");\n                    alert(data.msg);\n                }\n            });\n        });\n<\/code><\/pre>\n<p>The $(&#8216;userfile&#8217;).val(blob); gives me a &#8220;Uncaught Error: InvalidStateError: DOM Exception 11 &#8221; Why?<\/p>\n<p>Thanks<\/p>\n<p>Katrijne<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-15 09:07:17. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Can anyone tell me how I can store a blob on the server with an ajax call? I have tried many things but none of them work. And I cannot find any good information about this. This is where I want to send the blob class Ajax extends CI_Controller { function __construct() { parent::__construct(); $this-&gt;load-&gt;helper(&#8216;url&#8217;); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1377","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1377"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1377\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}