Skip to main content

Using BOX API in PHP program
I want to upload a file.

But it doesn't work.
In the response, the message "The request was rejected because no multipart boundary was found" is returned.

Please tell me the possible causes.
The sample code below does not work.

 

 

$request = $_REQUEST->all();
$file_obj = $ request->file('file');
$originalFileName = $file_obj->getClientOriginalName();
$uploadFileName = $file_obj->getFileName();
$uploadFileFull = $file_obj->getPathName();
$uploadFileSize = $file_obj->getSize();

 

$param_attributes = array('name' => $originalFileName, 'parent' => array('id' => '0'));
$param_file = "@".$originalFileName;
$param = array('attributes' => $param_attributes, 'file' => $param_file);

$param_json = json_encode($param);

 

$header = array("Authorization?Bearer { 'access_token' }", "Content-Type?multipart / form-data");

$ch = curl _init( "https://api.box.com/2.0/files/content" );
cur_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $param_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);

 


Be the first to reply!

Reply