这是 PHP 中的库代码,用于使用 laravel 框架在 dropbox-sdk(file-Client.php) 中上传文件。
我会在我的保管箱控制器中调用以下函数。
function uploadFile($path, $writeMode, $inStream, $numBytes = null)
{
Path::checkArgNonRoot("path", $path);
WriteMode::checkArg("writeMode", $writeMode);
Checker::argResource("inStream", $inStream);
Checker::argNatOrNull("numBytes", $numBytes);
// If we don't know how many bytes are coming, we have to use chunked upload.
// If $numBytes is large, we elect to use chunked upload.
// In all other cases, use regular upload.
if ($numBytes === null || $numBytes > self::$AUTO_CHUNKED_UPLOAD_THRESHOLD) {
$metadata = $this->_uploadFileChunked($path, $writeMode, $inStream, $numBytes,
self::$DEFAULT_CHUNK_SIZE);
} else {
$metadata = $this->_uploadFile($path, $writeMode,
function(Curl $curl) use ($inStream, $numBytes) {
$curl->set(CURLOPT_POST, true);
$curl->set(CURLOPT_INFILE, $inStream);
$curl->set(CURLOPT_INFILESIZE, $numBytes);
});
}
return $metadata;
}
反过来使用此功能。
private function _uploadFile($path, $writeMode, $curlConfigClosure)
{
Path::checkArg("path", $path);
WriteMode::checkArg("writeMode", $writeMode);
Checker::argCallable("curlConfigClosure", $curlConfigClosure);
$url = $this->buildUrlForGetOrPut(
$this->contentHost,
$this->appendFilePath("2/files/upload", $path),
$writeMode->getExtraParams());
$curl = $this->mkCurl($url);
$curlConfigClosure($curl);
$curl->set(CURLOPT_RETURNTRANSFER, true);
$response = $curl->exec();
if ($response->statusCode !== 200) throw RequestUtil::unexpectedStatus($response);
return RequestUtil::parseResponseJson($response->body);
}
我最近将网址从 V1 升级到 V2。我现在收到此错误,无法找到此错误的根本原因。
我什至尝试对保管箱 url 进行硬编码并将其放入 curl 请求中,但没有用。任何建议、帮助甚至引导都是救命稻草。