Attachment Improvements By Xon

Attachment Improvements By Xon 2.6.1

No permission to download
We've implemented this on a site that's been serving attachments through Wasabi while the site is served through Cloudflare. There is a CNAME record, proxied through Cloudflare, that points to the Wasabi bucket, and the XF internalDataUrl is set to this CNAME. This is all working fine. Attachments are loading without issue.

My next question is how to make Cloudflare cache the responses from Wasabi. The goal is to allow XF to deal with the permission check, but then once nginx hits up our CNAME (Which in turn loads from Wasabi), for Cloudflare to cache that static image response from Wasabi, to speed up future accesses for visitors, and to lessen our data transfer out of Wasabi.

What do we need to do to make that happen?

Edit: We set up a CF Page rule for xfdata-internal.site.com to cache everything, then enabled the Debug log so we could see what was being requested. When we requested that proxied URL in our browser, we got a CF-Cache-Status: hit header, so I guess it's successfully caching the responses from Wasabi, even if the site.com/attachments/* request isn't being shown as cached. Does that sound right, Xon?
 
Last edited:
While I can upload and show svg files in frontend, can you also let me upload any svg files in ACP?

For example, I can't seem to upload a svg file for node icons..

1655226372598.webp
 
I'll need to look into that, not sure when I'll be able to schedule it

Also, I found it's not possible to upload SVG files by the 'Drop Image' button in text editor. I doesn't show SVG files in Windows Explorer. I need to change to *.* to show those files. But still, when I choose an SVG file to upload, it shows me an 'Image file type in invalid error'.

But I can do it with the 'Attach files' button.

1655253275548.png

I have SVG included in allowed image attachment file extensions in attachment options:

1655253353756.png
 
Is this add-on working with the latest version of XF (v2.2.9)? I can attach SVGs to posts but I can no longer insert them in the body.
 
Is this add-on working with the latest version of XF (v2.2.9)? I can attach SVGs to posts but I can no longer insert them in the body.
Apparently the issue has to do with XenForo and PHP 8.1. The add-on works as expected under PHP 8.0.
 
Is this add-on working with the latest version of XF (v2.2.9)? I can attach SVGs to posts but I can no longer insert them in the body.
Can you share a sample svg that has the problem? The actual contents matters due to some of the processing logic.
 
Can you share a sample svg that has the problem? The actual contents matters due to some of the processing logic.
It wasn't working only under PHP 8.1. I simply couldn't insert any SVGs in posts. However, the SVGs that were inserted prior to switching to PHP 8.1 were in place and showing.

I sent a ticket to XenForo and they confirmed the software is not yet ready for PHP 8.1.

I switched back to PHP 8.0 and all is working as expected. Thank you very much for this add-on!
 
  • Like
Reactions: Xon
For me; attaching an SVG via "attach files" works but the drop & drag support doesn't work with the latest XF.

:edit: This is a Froala bug, but I've reported it to XF to make a workaround.
 
Last edited:
Amazing - this works with X-SendFile too by simply changing the two instances of X-Accel-Redirect to X-Sendfile - woo!

Small request would be for a toggle in a later version to pick :)

Note: X-Sendfile works differently to X-Accel-Redirect in the sense that it requires a full file path to be returned rather than a url - so you will need to set 'internalDataUrl' to the actual disk path to the internal_data folder. (This also means it will only work for locally attached files)
 
Last edited:
Amazing - this works with X-SendFile too by simply changing the two instances of X-Accel-Redirect to X-Sendfile - woo!

Small request would be for a toggle in a later version to pick :)

Note: X-Sendfile works differently to X-Accel-Redirect in the sense that it requires a full file path to be returned rather than a url - so you will need to set 'internalDataUrl' to the actual disk path to the internal_data folder. (This also means it will only work for locally attached files)
Do you happen to have an example of your use of X-Sendfile?
 
Had this error logged while using Cloudflare R2 for storing the attachments:

Code:
ErrorException: [E_WARNING] fseek(): Stream does not support seeking src/addons/SV/AttachmentImprovements/PartialResponseStream.php:55
Generated by: Matt Dec 5, 2022 at 9:37 AM
Stack trace
#0 [internal function]: XF::handlePhpError(2, '[E_WARNING] fse...', '/home/admin/dom...', 55)
#1 src/addons/SV/AttachmentImprovements/PartialResponseStream.php(55): fseek(Resource id #390, 1229876)
#2 src/addons/SV/AttachmentImprovements/PartialResponseStream.php(105): SV\AttachmentImprovements\PartialResponseStream->readChunks(true)
#3 src/addons/SV/AttachmentImprovements/PartialResponseStream.php(41): SV\AttachmentImprovements\PartialResponseStream->getContents()
#4 src/XF/Http/Response.php(455): SV\AttachmentImprovements\PartialResponseStream->getLength()
#5 src/XF/Http/Response.php(281): XF\Http\Response->sendBody()
#6 src/XF.php(574): XF\Http\Response->send(Object(XF\Http\Request))
#7 index.php(20): XF::runApp('XF\\Pub\\App')
#8 {main}

Not using nginx, but Litespeed Enterprise with this one.
 
Had this error logged while using Cloudflare R2 for storing the attachments:

Code:
ErrorException: [E_WARNING] fseek(): Stream does not support seeking src/addons/SV/AttachmentImprovements/PartialResponseStream.php:55
Generated by: Matt Dec 5, 2022 at 9:37 AM
Stack trace
#0 [internal function]: XF::handlePhpError(2, '[E_WARNING] fse...', '/home/admin/dom...', 55)
#1 src/addons/SV/AttachmentImprovements/PartialResponseStream.php(55): fseek(Resource id #390, 1229876)
#2 src/addons/SV/AttachmentImprovements/PartialResponseStream.php(105): SV\AttachmentImprovements\PartialResponseStream->readChunks(true)
#3 src/addons/SV/AttachmentImprovements/PartialResponseStream.php(41): SV\AttachmentImprovements\PartialResponseStream->getContents()
#4 src/XF/Http/Response.php(455): SV\AttachmentImprovements\PartialResponseStream->getLength()
#5 src/XF/Http/Response.php(281): XF\Http\Response->sendBody()
#6 src/XF.php(574): XF\Http\Response->send(Object(XF\Http\Request))
#7 index.php(20): XF::runApp('XF\\Pub\\App')
#8 {main}

Not using nginx, but Litespeed Enterprise with this one.
Can you open a ticket on my site, and provide a sanitized snippet from src/config.php of how you are using Cloudflare R2 ?
 
Xon updated Attachment Improvements By Xon with a new update entry:

2.5.0 - Security & Bugfix update

  • Only support range-requests for local files, not remote filesystems as the underlying library does not support determining if this is suppotred.
  • Ensure attachments SVGs are only served as images if it is known to be valid, and inline display of SVGs is permitted.
  • Remove non-implemented "Allowed Image Attachment File Extensions" option
  • Add "Allow inline display of SVG image attachments" option, defaults to off (breaking change)

Read the rest of this update entry...
 
Contributing features or bug fixes
Please create a Github Pull request via the "More Information" link.

Where is the "More information" link? I would like to add in the X-Sendfile option :)
 
  • Like
Reactions: Xon
I’m getting this fatal error:
Trait "SV\StandardLib\InstallerHelper" not found in /…/src/addons/SV/AttachmentImprovements/Setup.php on line 11
when trying to either install or upgrade to v2.5.0.
 
Top Bottom