I am trying to upload files to a RESTful WEB API using HTTP POST and cURL. Following is the code block that I am trying at this moment. With this everything just works fine other than one problem, it stores the data in the default database principal. Which I want is to upload the file to the database principal the user is currently using. I need to know two things -
Is there a way to specify which database principal to use in the web server in cURL header or is there any cURL option available to specify that so that cURL POST uploads the data in the mentioned database principal?
I have never used cURL before, is it the best option to upload files using multipart/form-data to a RESTful WEB API by HTTP POST?
for($i=0; $i<count($_FILES['files_to_upload']['name']); $i++) { if(!empty($_FILES['files_to_upload']['tmp_name'][$i])) { $ext = pathinfo($_FILES['files_to_upload']['name'][$i], PATHINFO_EXTENSION); $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $_FILES['files_to_upload']['tmp_name'][$i]); $data_for_api = [ 'rel_type' => PROJECTS_REL_TYPE, 'rel_key' => $ktr, 'category' => $_POST['file_category'][$i], 'filename' => $_POST['file_name'][$i].".".$ext, 'file-form-data' => new CURLFile($_FILES['files_to_upload']['tmp_name'][$i],$mime,$_FILES['files_to_upload']['tmp_name'][$i]), 'description' => $_POST['file_name'][$i], 'uploader' => $this->session->userdata(RESNR) ]; $ch = curl_init(INTERNAL_API_URL.POST_A_FILE); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_for_api); if(!curl_exec($ch)) { echo curl_error($ch); } curl_close($ch); } }