Problem/Motivation

Cloudinary's stream wrapper does not support the move operation. I belive this is caused by the fact that \Drupal\cloudinary_stream_wrapper\StreamWrapper\CloudinaryStreamWrapper::stat() does not properly report that the directory/folder exists when drupal prepares the directory in \Drupal\Core\File\FileSystem::move().

I believe the root cause of this issue is that \Drupal\cloudinary_stream_wrapper\StreamWrapper\CloudinaryStreamWrapper::loadResource() does not load directory resources as it should.

Steps to reproduce

Try to create a cloudinary image media entity via Drupal core's JSON:API, and the second request will throw the following error:

The specified file 'temporary://filexkpCkd' could not be copied because the destination directory 'cloudinary://2022-12' is not properly configured. This may be caused by a problem with file or directory permissions.

Example:

# USING JETBRIANS HTTP CLIENT

### Step 1: Upload the image file to drupal with json api.
POST https://example.com
    /jsonapi
    /media
    /cloudinary_image
    /field_media_cloudinary_image
Authorization: Basic username password
Content-Type: application/octet-stream
Accept: application/vnd.api+json
Content-Disposition: file; filename="ReplaceMe.png"

< /Users/christophersnyder/LoremIpsum/ReplaceMe.png


### Step 2: Create the image media entity with the json api, using the file id/uuid from the previous step's response.
POST https://example.com
    /jsonapi
    /media
    /cloudinary_image
Authorization: Basic username password
Accept: application/vnd.api+json
Content-Type: application/vnd.api+json

{
  "data": {
    "type": "media--cloudinary_image",
    "attributes": {
      "name": "REPLACE ME"
    },
    "relationships": {
      "field_media_cloudinary_image": {
        "data": {
          "type": "file--file",
          "id": "c777c1c4-c991-4b82-b60b-018fe2ddc638",
          "meta": {
            "alt": "alt",
            "title": "title"
          }
        }
      }
    }
  }
}

Proposed resolution

Fix \Drupal\cloudinary_stream_wrapper\StreamWrapper\CloudinaryStreamWrapper::loadResource() so it can load file/folder resources from cloudinary.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork cloudinary-3326946

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ChrisSnyder created an issue. See original summary.

chrissnyder’s picture

This is my initial attempt at correcting the issue. This change has resolved the issue, allowing Cloudinary image media items to be created using JSON API

chrissnyder’s picture

Status: Active » Needs review
rohit.rawat619’s picture

Assigned: Unassigned » rohit.rawat619
Status: Needs review » Active
rohit.rawat619’s picture

Assigned: rohit.rawat619 » Unassigned
Status: Active » Needs review
StatusFileSize
new55.13 KB
chrissnyder’s picture

@RohitRawat676 I don't see how the patch you uploaded relates to this issue. I think it was intended for #2942513: Cloudinary crop image effect.