Skip to content
This repository has been archived by the owner on Feb 14, 2020. It is now read-only.

Local upload doesn't work - fix inside #3

Open
juresrpcic opened this issue Oct 28, 2016 · 0 comments
Open

Local upload doesn't work - fix inside #3

juresrpcic opened this issue Oct 28, 2016 · 0 comments

Comments

@juresrpcic
Copy link

Thanks for the great plugin!

I came across an issue where local uploading didn't work - the plugin expects a publicly accessible server (which localhost is not).

Here's the fix for services/NpCloudinary_CloudinaryService.php

`class NpCloudinary_CloudinaryService extends BaseApplicationComponent
{

/*
// OLD UPLOAD FUNCTION
public function uploadAsset(AssetFileModel $savedAsset)
{
try {
    \Cloudinary\Uploader::upload($savedAsset->url, [
        'public_id' => $this->getAssetHandle($savedAsset),
    ]);
} catch (\Cloudinary\Error $e) {
    $this->handleError($e->getMessage());
}
}
*/

// NEW SUPPORT FUNCTION FOR UPLOAD FUNCTION
private function getSourceFileSystemPath(LocalAssetSourceType $sourceType = null)
{
    $path = is_null($sourceType) ? $this->getBasePath() : $sourceType->getBasePath();
    $path = IOHelper::getRealPath($path);
    return $path;
}

// NEW UPLOAD FUNCTION
public function uploadAsset(AssetFileModel $savedAsset)
{
    // get the local path to asset first
    $fileSourceType = craft()->assetSources->getSourceTypeById($savedAsset->getSource()->id);
    $fileLocalPath = $this->getSourceFileSystemPath($fileSourceType).$savedAsset->getPath();
    // upload
    try {
        \Cloudinary\Uploader::upload($fileLocalPath, [
            'public_id' => $this->getAssetHandle($savedAsset),
        ]);
    } catch (\Cloudinary\Error $e) {
        $this->handleError($e->getMessage());
    }
}`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant