not working with codeigniter api #1095

Open
opened 2019-06-03 07:58:47 +00:00 by NikhilGangurde · 0 comments
NikhilGangurde commented 2019-06-03 07:58:47 +00:00 (Migrated from github.com)

here is my Codeigniter upload function

public function do_upload()
{
	$config['upload_path']          = './';
	$config['allowed_types']        = 'gif|jpg|png|doc|txt|jpeg|pdf';
	$config['max_size']             = 2048000;
	echo "hello";
	$this->load->library('upload');
	$this->upload->initialize($config);
	if ( ! $this->upload->do_upload('userfile'))
	{
			$error = array('error' => $this->upload->display_errors());
			echo print_r($error);
	}
	else
	{
			$data = array('upload_data' => $this->upload->data());
			echo json_encode($data);
	}
}

and ng2-file-upload config

const URL : string = 'http://localhost/CodeIgniter/index.php/upload/do_upload';

public uploader:FileUploader = new FileUploader({url: URL,
     isHTML5:true,
    disableMultipart:true,
    autoUpload:false,
    method: 'POST',
    headers: [
      { name: 'Content-Type', value: 'multipart/form-data' },
      { name: 'Access-Control-Allow-Origin', value: 'http://localhost:4200' },
      { name: 'Access-Control-Allow-Methods', value: 'POST'},
      { name: 'Access-Control-Allow-Credentials', value: 'true'}
   ],
   itemAlias: 'file'});

request returns 200 ok but file not uploaded to the folder

here is my Codeigniter upload function public function do_upload() { $config['upload_path'] = './'; $config['allowed_types'] = 'gif|jpg|png|doc|txt|jpeg|pdf'; $config['max_size'] = 2048000; echo "hello"; $this->load->library('upload'); $this->upload->initialize($config); if ( ! $this->upload->do_upload('userfile')) { $error = array('error' => $this->upload->display_errors()); echo print_r($error); } else { $data = array('upload_data' => $this->upload->data()); echo json_encode($data); } } and ng2-file-upload config const URL : string = 'http://localhost/CodeIgniter/index.php/upload/do_upload'; public uploader:FileUploader = new FileUploader({url: URL, isHTML5:true, disableMultipart:true, autoUpload:false, method: 'POST', headers: [ { name: 'Content-Type', value: 'multipart/form-data' }, { name: 'Access-Control-Allow-Origin', value: 'http://localhost:4200' }, { name: 'Access-Control-Allow-Methods', value: 'POST'}, { name: 'Access-Control-Allow-Credentials', value: 'true'} ], itemAlias: 'file'}); request returns 200 ok but file not uploaded to the folder
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#1095