500 Erorr使用AcrCloud RESTful api php上传音频文件

时间:2017-01-24 10:09:46

标签: php curl acrcloud

我正在尝试使用php上传音频文件我得到了这个 我在邮差中尝试了相同的凭据,但它确实有效。 我无法找出问题所在

我正在关注ACRCloud文档here

  HTTP/1.1 100 Continue
    < HTTP/1.1 500 Internal Server Error
    < Server: openresty/1.9.7.4
    < Date: Mon, 23 Jan 2017 16:51:29 GMT
    < Content-Type: application/json; charset=UTF-8
    < Transfer-Encoding: chunked
    < Connection: keep-alive
    < X-Powered-By: PHP/5.6.21
    < X-Rate-Limit-Limit: 600
    < X-Rate-Limit-Remaining: 599
    < X-Rate-Limit-Reset: 0

    HTTP error before end of send, stop sending
    <
    Closing connection 0`

mycode

$request_url = 'https://api.acrcloud.com/v1/audios';
$http_method = 'POST';
$http_uri = '/v1/audios';
$timestamp = time();
$signature_version = '1';
$account_access_key = '';
$account_access_secret = '';
$string_to_sign =
$http_method . "\n" .
$http_uri . "\n" .
$account_access_key . "\n" .
$signature_version . "\n" .
$timestamp;
$signature = base64_encode(hash_hmac("sha1", $string_to_sign, $account_access_secret, true));
$realpath = realpath('uploads/*****.mp3');

    if(class_exists('\CURLFile'))
        $cfile = new \CURLFile($realpath, "audio/mp3", basename($realpath));
    else
        $cfile = '@' . $realpath;
    $fields = array(
        'audio_id' => '30007',
        'title' => 'aya number 19',
        'audio_file' => $cfile,
        'bucket_name' => 'whatever',
        'data_type' => 'audio',  // if you upload fingerprint file please set 'data_type'=>'fingerprint'
        'custom_key[0]' => 'track_id',
    );
    $headerArray = array();
    $headers = array(
        'access-key' => $account_access_key,
        'signature' => $signature,
        'signature-version' => '1',
        'timestamp' => $timestamp,
    );
    foreach( $headers as $n => $v ) {
        $headerArr[] = $n .':' . $v;
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $request_url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    $verbose = fopen('php://temp', 'w+');
    curl_setopt($ch, CURLOPT_STDERR, $verbose);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
    $result = curl_exec($ch);
    if ($result === FALSE) {
        printf("cUrl error (#%d): %s<br>\n", curl_errno($ch),
            htmlspecialchars(curl_error($ch)));
    }
    rewind($verbose);
    $verboseLog = stream_get_contents($verbose);

    echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";
    dd($result);
    curl_close($ch);

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

我发现了:

1-您必须使用本地文件

2- Curl采用绝对文件路径

3-如果你使用custom_key [0],你必须在custom_value [0]之后添加

现在它的工作得益于支持

希望能帮到某人