Attachment Improvements By Xon

Attachment Improvements By Xon 2.6.1

No permission to download
Code:
XenForo v2.1.8 Patch 2   

Centos 7

# php -v

PHP 7.3.16 (cli) (built: Apr 10 2020 03:44:33) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.3.16, Copyright (c) 1998-2018 Zend Technologies

    with Zend OPcache v7.3.16, Copyright (c) 1999-2018, by Zend Technologies

I found the cause of the problem.

If I set the value to 558 or smaller, then the svg attachment works. 559 or above doesn't work.



1586937106993.png

However, further lower the value will crop the image:

1586937433536.png
1586937495715.png

Insert Thumbnail will be cropped like this:

1586937569115.png
 
after I turn on X-Accel the browser just downloaded the attachments, Chrome's network log says content-type is application/octet-stream, any idea how to debug this?
 
after I turn on X-Accel the browser just downloaded the attachments, Chrome's network log says content-type is application/octet-stream, any idea how to debug this?
this is caused by my site going through Cloudflare, trying to go direct, the server it's on its knee the moment I enable this, took 10 minutes spamming the save settings button turning it off...

this addon is dangerous...

Screen Shot 2020-07-17 at 10.34.57.png
 
The x-accel configuration is disabled by default as it is an advanced option which requires close integration with nginx. There is a "debug log" feature which reports the URL's it redirects to exposed when the site is in debug mode.

after I turn on X-Accel the browser just downloaded the attachments, Chrome's network log says content-type is application/octet-stream, any idea how to debug this?
This add-on shouldn't directly affect the content-type, what was it before? This may be your nginx configuration resetting the content type, an that is well beyond the free support I offer for this add-on.

this is caused by my site going through Cloudflare, trying to go direct, the server it's on its knee the moment I enable this, took 10 minutes spamming the save settings button turning it off...

this addon is dangerous...

View attachment 230552


This is expected behaviour. It is up to you to set caching flags in nginx layer as required to signal to cloudflare to cache. By default attachments will not be cached anyway, and XF doesn't directly expose the URL as a filename which allow clouldflare auto-caching to work.

Cloudflare are also not shy about booting you if you are aggressively caching not-html content on free plans.
 
no, I mean if my site was going through CF then the attachments would trigger download when I turned the option on, not sure how or why CF is messing with the content-type header...

if my site was not going through CF, then turning the option on made the server basically crash, the attachments show up as normal though (on the first few successful requests before the server stop responding)

and my nginx server is beefy, 32 cores with 128GB memory...
 
Is it 2.2 ready?

// never mind. I just installed with the X-accel enabled and found no problem so far.
 
Last edited:
I was rewriting my nginx configurations tonight and I came across a module that could be of use in attachments...

gzip_static https://nginx.org/en/docs/http/ngx_http_gzip_static_module.html

What would be the possibility of pre-gzipping attachment data so when its served via x-accel we can save on gzip cpu cycles (thus being able to use higher compression without crippling the cpu).

I found an article on ServerFault that gives an example of how it can be achieved with PHP... what are your thoughts?

Only downside I could foresee is delivering gzipped data to a client that doesn't support it (thus needing a fallback script or fallback file)
 
It really depends on the content being served. If it is zips/jpg/png, there isn't really any point trying to compress it.
 
Hi Guys and @Xon !

In the tutorals for Digital OCean S3 you described this:


A internalDataUrl stanza l must be added to config.php like the externalDataUrl described in the tutorial

PHP:
$config['internalDataUrl'] = function($externalPath, $canonical)
{
return 'internal_data_s3/..../internal_data/' . $externalPath;
};


nginx config must be updated with a new internal_data_s3 block;
PHP:
location ~* /internal_data_s3/(.?)://(.?)/(.*) {
internal;
set $xfEtag $upstream_http_etag;
set $download_protocol $1;
set $download_host $2;
set $download_path $3;
set $download_url $download_protocol://$download_host/$download_path;

resolver 127.0.0.1 ipv6=off;
proxy_set_header Host $download_host;
proxy_set_header Authorization '';
proxy_set_header Cookie '';
proxy_max_temp_file_size 0;
proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirect;

proxy_pass $download_url$is_args$args;

proxy_hide_header Content-Disposition;
proxy_hide_header Content-Type;
proxy_hide_header Etag;
proxy_hide_header x-amz-request-id;

add_header Etag $xfEtag;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
}

location @handle_redirect {
resolver 127.0.0.1 ipv6=off;
set $saved_redirect_location '$upstream_http_location';
proxy_pass $saved_redirect_location;
}

My question is:
which part of these do I have to edit?
I assume at the first part only the "'internal_data_s3/..../internal_data/'" have to be edited so that it will mach my DO link?
The rest can be left alone?


And for nginx ... Im on ASA server and wasnt able to find any nginx config file ... so, do I have to add this part? Do I have to ignore it? Do I have to create a ngnix file? Do I have to add this part to the config file as the rest?
If I have to add it to anywhere is there any part of it that needs to be edited?

Thanks a lot for the help!
 
Just wondering if this error is connected to this addon???

Code:
Server error log

    LogicException: Temp hash must be specified if no content is specified. src/XF/Entity/Attachment.php:270

    Generated by: DavidUK Feb 3, 2021 at 12:01 PM

Stack trace

#0 src/XF/Mvc/Entity/Entity.php(1355): XF\Entity\Attachment->_preSave()
#1 src/XF/Mvc/Entity/Entity.php(1208): XF\Mvc\Entity\Entity->preSave()
#2 src/XF/Service/Attachment/Preparer.php(267): XF\Mvc\Entity\Entity->save()
#3 src/XF/Service/Attachment/Preparer.php(29): XF\Service\Attachment\Preparer->insertTemporaryAttachment(Object(SV\AttachmentImprovements\XF\Attachment\Post), Object(SV\AttachmentImprovements\XF\Entity\AttachmentData), '[{"id":"458869-...', Object(XF\FileWrapper))
#4 src/XF/Attachment/Manipulator.php(170): XF\Service\Attachment\Preparer->insertAttachment(Object(SV\AttachmentImprovements\XF\Attachment\Post), Object(XF\FileWrapper), Object(SV\ConversationEssentials\XF\Entity\User), '[{"id":"458869-...')
#5 src/XF/Pub/Controller/Attachment.php(89): XF\Attachment\Manipulator->insertAttachmentFromUpload(Object(XF\Http\Upload), NULL)
#6 src/XF/Mvc/Dispatcher.php(350): XF\Pub\Controller\Attachment->actionUpload(Object(XF\Mvc\ParameterBag))
#7 src/XF/Mvc/Dispatcher.php(257): XF\Mvc\Dispatcher->dispatchClass('XF:Attachment', 'Upload', Object(XF\Mvc\RouteMatch), Object(SV\AttachmentImprovements\XF\Pub\Controller\Attachment), NULL)
#8 src/XF/Mvc/Dispatcher.php(113): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(SV\AttachmentImprovements\XF\Pub\Controller\Attachment), NULL)
#9 src/XF/Mvc/Dispatcher.php(55): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#10 src/XF/App.php(2326): XF\Mvc\Dispatcher->run()
#11 src/XF.php(488): XF\App->run()
#12 index.php(20): XF::runApp('XF\\Pub\\App')
#13 {main}

Request state

array(4) {
  ["url"] => string(131) "/attachments/upload?type=post&context[thread_id]=31023&hash=%5B%7B%22id%22%3A%22458869-0%22%7D%2C%7B%22id%22%3A%22458889-0%22%7D%5D"
  ["referrer"] => string(62) "https://cafesaxophone.com/threads/todays-buy-what-is-it.31023/"
  ["_GET"] => array(3) {
    ["type"] => string(4) "post"
    ["context"] => array(1) {
      ["thread_id"] => string(5) "31023"
    }
    ["hash"] => string(37) "[{"id":"458869-0"},{"id":"458889-0"}]"
  }
  ["_POST"] => array(3) {
    ["_xfToken"] => string(8) "********"
    ["_xfResponseType"] => string(4) "json"
    ["_xfWithData"] => string(1) "1"
  }
 
The attachment hash looks very weird;
Code:
["hash"] => string(37) "[{"id":"458869-0"},{"id":"458889-0"}]"

None of my add-ons should interfere with this, and I haven't hit this in my XF2.2 testing with all my add-ons.
 
FWIW, we had our first ever report of that error on Monday via ticket.
This add-on was listed in the trace, along with XFMG.

Code:
#4 src/XF/Attachment/Manipulator.php(170): XF\Service\Attachment\Preparer->insertAttachment(Object(XFMG\XF\Attachment\Post), Object(XF\FileWrapper), Object(SV\SearchImprovements\XF\Entity\User), '[{"id":"5226769...')

We were unable to conclude what the actual cause of the error was and as it can't be reproduced on demand, it makes it difficult to troubleshoot.
(That and we don't have a copy of the add-on so can't do any local testing.)
 
Top Bottom