1

I'm creating an application in which the user will upload a binary file onto the server and the admin can view and verify the file. But the problem I am having is that the FileUploader class in angular is not accepting the file type .bin and not communicating it to my codeigniter backend server.

I have already tried multiple extension forms in the code like bin,application/octet-stream and even '*' so that it can accept all types of files. But none of it worked

MY angular code to upload file using FileUploader

var id = ($scope.id = new FileUploader({
      queueLimit: 1,
      url: "server/index.php/Upload/file"
    }));

// FILTERS

// a sync filter
id.filters.push({
  name: "syncFilter",
  fn: function(item /*{File|FileLikeObject}*/, options) {
    if (this.queue.length > 0) {
      id.clearQueue();
    }
    return this.queue.length < 1;
  }
});

// an async filter
id.filters.push({
  name: "asyncFilter",
  fn: function(item /*{File|FileLikeObject}*/, options, deferred) {
    setTimeout(deferred.resolve, 1e3);
  }
});

id.filters.push({
  name: "imageFilter",
  fn: function(item /*{File|FileLikeObject}*/, options) {
    var type = "|" + item.type.slice(item.type.lastIndexOf("/") + 1) + "|";
    return "|bin|".indexOf(type) !== -1;
  }
});

MY codeigniter file funtion which uploads the file and in return responds with its name

public function file() {
        $data = array();
        $config['upload_path'] = 'public/files';
        $config['allowed_types'] = 'bin';
        $config['max_size'] = 10000000;
        $config['max_width'] = 1920;
        $config['max_height'] = 1280;
        $file_name = $_FILES["file"]['name'];
        $newfile_name = preg_replace('/[^A-Za-z0-9]/', "", $file_name);

        $config['file_name'] = time() . $newfile_name;
        $this->load->library('upload', $config);
        $this->upload->do_upload('file');


        $data = $this->upload->data();
        echo json_encode($data);
        exit();
    }
5
  • What do you mean when say FileUploader is not accepting the .bin file? Is there an error message? Commented Aug 8, 2019 at 18:20
  • FileUploader is not a builtin JavaScript class. What library are you using? With AngularJS binary files are normally uploaded with the $http Service. Commented Aug 8, 2019 at 18:25
  • no error msg but it works with other file types but whenever i upload a binary type file it doesn't communicate it with the backend server file so no response from the codeigniter controller Commented Aug 9, 2019 at 5:45
  • angular-file-upload library. @georgeawg do you have any examples related to binary files as I couldn't find one. Commented Aug 9, 2019 at 5:48
  • Angular-file-upload is unmaintained. Consider using ng-file-upload. See also File Upload using AngularJS Commented Aug 9, 2019 at 7:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.