akeeba / plg_filesystem_s3

Integrate Amazon S3, CloudFront and Amazon S3–compatible storage with Joomla!'s Media Manager
GNU General Public License v3.0
6 stars 2 forks source link

I can't create folders in Cloudflare R2 #15

Closed alebak closed 5 months ago

alebak commented 5 months ago

Hello,

When I try to create a folder using the Joomla Multimedia Manager, I get the following error:

'Error creating folder.' 'AkeebaS3Connector::putObject(): [500] MissingContentLength:You must provide the Content-Length HTTP header. Debug info: 'SimpleXMLElement Object ( [Code] => MissingContentLength [Message] => You must provide the Content-Length HTTP header. )'

Steps to reproduce the issue

The steps I have performed are as follows:

  1. Select the previously configured bucket.
  2. I click on the 'Create new folder' button.
  3. In the pop-up I enter the name of the folder and click on the 'Create' button.

Expected result

Close the pop-up after clicking the 'Create' button and the folder is created in the bucket.

Actual result

After performing these steps, the pop-up does not close and in the background you can see the previously mentioned messages.

image

System information

alebak commented 5 months ago

UPDATE

I'm seeing that in Cloudflare's R2 that there is no concept of folder, but uses them as a prefix in the file name

image

image

Internally, the object (file) name is videos%2Fhero-bg-video.mp4, where videos%2F is the prefix. So, in this case, I don't know if this issue would be a bug, a new feature or I simply omitted some parameter in the plugin configuration.

image

nikosdion commented 5 months ago

You are correct that S3 is a key-value BLOB storage. It doesn't have the concept of folders and files. The API understands prefix separators, the default one being /. Therefore foo/bar/baz.bat would appear as a "file" named baz.bat inside the "folder" bar which is inside the "folder" foo which is inside the "root" of the bucket's "filesystem". The parts between prefix separators are treated as "folders" and "files".

The canonical implementation of the S3 API as provided by Amazon itself allows the creation of empty "folders" with a kind of hack. If you create an entry with a key that ends in a prefix separator (e.g. foo/bar/) and no content it will be treated as an empty "folder".

Most S3-compatible implementations reserve the same treatment of these special items, therefore we implemented our createFolder method around it.

It appears that R2 does not accept items with no content. They insist on having a Content-Length despite the fact we send no content. This means you cannot create folders. I wouldn't say it's a bug, I would say it's a way that R2 differs from the canonical S3 implementation.