首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >500使用AcrCloud RESTful api php上传音频文件时出错

500使用AcrCloud RESTful api php上传音频文件时出错
EN

Stack Overflow用户
提问于 2017-01-24 18:09:46
回答 1查看 324关注 0票数 2

我正在尝试使用php上传音频文件,我得到了这个,我在Postman中尝试了相同的凭据,它起作用了。我找不到出了什么问题

我正在关注ACRCloud文档here

代码语言:javascript
复制
  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

代码语言:javascript
复制
$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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-30 21:30:00

我发现:

1-您必须使用本地文件

2- Curl采用绝对文件路径

3-如果您使用custom_key,则必须在它之后添加custom_value

多亏了支持,它现在才能正常工作

希望能帮助到某些人

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41825358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档