This is library code in PHP for uploading a file in dropbox-sdk(file- Client.php), using laravel framework.
I would call below function in my dropbox controller.
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;
}
which in turn uses this function.
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);
}
I have recently upgraded urls to V2 from V1. I'm getting this error now an couldn't find root cause for this error.
I even tried to hardcode the dropbox url and put it in curl request but no use. Any suggestions, help or even lead is a life saver.