Hello,
I have a strange error when trying to upload OTA from a app via a PHP script.
Below is the script:
<?
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$target_url = 'https://mdash.net/api/v2/devices/'.'device_name'.'/ota?access_token='.'token';
$file_name_with_full_path = realpath('20200202-162927.zip');
$post = array('file'=>'@'.$file_name_with_full_path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
http_response_code(200);
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
}
echo $result;
curl_close ($ch);
?>
Above script works OK if php from hosting service is set to 5.4, but if I set php to 5.6 i get folowing response > {"message":"Internal Server Error"}
Anny ideas?
lsm
March 3, 2020, 1:30pm
2
Please debug it - see https://stackoverflow.com/questions/3757071/php-debugging-curl
Include the debug output. We need to see what PHP sends to mDash.
lsm
March 3, 2020, 3:31pm
4
I do not see what’s inside form data, but I can see a big difference in content length - 192 bytes vs 961869 bytes. The newer version , apparently, does not include the file. Maybe it sends only file path, but not the file contents.
Yes, after ponting me to debug the curl output I observe the same thing and also managed to fix the issue.
More details about the problem are detailed here cURL file uploads not working anymore after upgrade from PHP 5.5 to 5.6
New working code is here:
<?
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$target_url = 'https://mdash.net/api/v2/devices/'.'device name'.'/ota?access_token='.'token';
$file_name_with_full_path = realpath('20200202-162927.zip');
$post['file'] = curl_file_create($file_name_with_full_path, 'application/zip', '20200202-162927.zip');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
http_response_code(200);
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
}
echo $result;
curl_close ($ch);
?>
1 Like
lsm
March 3, 2020, 4:49pm
6
Cool, thanks for the background