0
api를 통해 파일을 업로드하는 데 다음 코드를 사용하고 있습니다. 하지만 업로드 한 후 파일 내용 유형이 잘못되었습니다 (단지 약 26 바이트). 콘텐츠 유형은 $ data_string의 길이가됩니다. 콘텐츠 길이를 업로드 파일의 파일 크기로 변경하려고했습니다. 하지만 그 후에는 API가 작동하지 않습니다. 어떤 코딩을 잘못 했습니까?PHP curl로 파일을 업로드 할 때 콘텐츠 길이 문제가 발생합니다.
$data = array("Content" => "file.wav"); //around 4mb
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'URL');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: audio/wav',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$data = curl_exec($ch);
curl_close($ch);