Spiria Posted November 27, 2021 Posted November 27, 2021 (edited) Hi, I have a lot of trouble figuring out what I am doing wrong when I try to send a file to a given address. If I send the file in a program similar to Postman, I get the confirmation I want. If I try a similar operation with WireHTTP(), the file is not sent, it seems... The attritute sent should be "file". $forms = wire('forms'); $form = $forms->get('application_lever_form'); $entryId = session()->get('entryId'); $entry = $forms->getEntry($entryId); $filename = $entry["attach_your_cv"][0]; $urlFile = $forms->getFileURL($form->id, $entry['id'], $filename); $url = "https://api.lever.co/v1/uploads)"; $http = new WireHttp(); $http->setHeader('Content-Type', 'multipart/form-data'); $http->setHeader('Authorization', 'Basic ' . $this->accessToken); $http->setData(['file', file_get_contents($urlFile)]); $result = $http->post($url); I have tried also this: $forms = wire('forms'); $entryId = session()->get('entryId'); $entry = $forms->getEntry($entryId); $filename = $entry["attach_your_cv"][0]; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); $url = "https://api.lever.co/v1/uploads)"; $http = new WireHttp(); $http->setHeader('Content-Type', 'multipart/form-data'); $http->setHeader('Authorization', 'Basic ' . $this->accessToken); $http->setData(['file', $contents]); $result = $http->post($url); What am I doing wrong? PS: The curl equivalent (which works from Postman) is: $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.lever.co/v1/uploads', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('file'=> new CURLFILE('/Users/guyverville/Downloads/Clipboard Data.txt')), CURLOPT_HTTPHEADER => array( 'Content-Type: multipart/form-data', 'Authorization: Basic ........' ), )); $response = curl_exec($curl); curl_close($curl); echo $response; Edited November 27, 2021 by Spiria added curl code
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now