在Dropbox

时间:2017-07-17 06:35:49

标签: php dropbox-api

我有一个功能,可以在我的网站上下订单后将产品图片上传到Dropbox。

我将路径名自定义为:

$dropBoxRoot = '/Comp#'.$user['company_id'].'/Prop#'.$user['object_id'].'/Order#'.$orderId.'/'.$product;

我使用getDelta函数检查了所述路径是否存在。

//let's assume $this-client has already instantiated
$checkIfFolderExist = $this->client->getDelta(null, $dropBoxRoot);

之后,我通过这样做上传了该图片:

//the actual path : /Comp#119/Prop#5/Order#120/Product1/image.png
$this->client->uploadFile($dropBoxRoot.'/'.$fileName, WriteMode::add(), $file, $size);

图像上传到保管箱中。我可以在路径中看到它,但在上传后,uploadFile函数返回一个异常:

(1/1) InvalidArgumentException

'path': bad path: must start with "/": "image.png"
 in Path.php (line 141)

如果有人遇到同样的情况,我想问你的意见。提前谢谢!

1 个答案:

答案 0 :(得分:0)

我刚发现,如果连接path参数,它将返回错误。

uploadFile函数中,我这样做了:

$dropBoxRoot.'/'.$fileName

所以我创建了一个新变量来连接最终路径:

$finalPath = $dropBoxRoot.'/'.$fileName;

$this->client->uploadFile($finalPath, WriteMode::add(), $file, $size);

所以这次它没有例外地返回。

相关问题