Dropbox API剥离MP3标签

时间:2015-02-09 22:06:10

标签: php upload mp3 dropbox-api

我正在将MP3的Centos目录与Dropbox共享文件夹同步。当我将MP3文件复制到Windows中的文件夹时,一切都很好。当我使用PHP脚本和REST接口从Centos上传文件时,它们的尺寸更大,并且缺少标签。我仍然可以播放这些文件,因此不是简单的文件损坏。我在PHP脚本中以二进制模式打开文件。这是相关的代码:

    $path = $this->dropboxPath($root, $subDir, $fileName);
    $uri = "https://api-content.dropbox.com/1/files_put/auto/$path";

    $lclPath = storage_path() . "/$root/$subDir/$fileName";

    $fd = fopen($lclPath, 'rb');

    $this->putDropbox($uri, [
        'overwrite' => 'true'
        ], $fd
    );

private function putDropbox($uri, $parms, $fd) {
    $uri = $uri . "?" . http_build_query($parms);
    $client = new GuzzleHttp\Client();

    $req = $client->createRequest('PUT', $uri, [
        'exceptions' => true,
        'body' => [
            'file_filed' => $fd
        ]
    ]);

    $req->setHeader('Authorization', 'Bearer ' . $this->token);

    try {
        $resp = $client->send($req);
        return $resp;
    }
    catch(Exception $e) {
        Log::error($e->getRequest());

        if($e->hasResponse()) {
            Log::error($e->getResponse());
        }
    }
}

0 个答案:

没有答案