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();
    }
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Khawaja Ali
  • 51
  • 1
  • 5
  • What do you mean when say FileUploader is not accepting the `.bin` file? Is there an error message? – georgeawg Aug 08 '19 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. – georgeawg Aug 08 '19 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 – Khawaja Ali Aug 09 '19 at 05:45
  • angular-file-upload library. @georgeawg do you have any examples related to binary files as I couldn't find one. – Khawaja Ali Aug 09 '19 at 05:48
  • Angular-file-upload is unmaintained. Consider using [ng-file-upload](https://stackoverflow.com/tags/ng-file-upload/info). See also [File Upload using AngularJS](https://stackoverflow.com/questions/18571001/file-upload-using-angularjs) – georgeawg Aug 09 '19 at 07:47

0 Answers0