Assets Admin Throwing Errors, not accepting uploads, and Causing Logout

Silverstripe 4

When I try to upload files in asset admin, the file seems to upload, but the preview link is broken, the preview link opens a 404, and when I try to publish the file I am receiving these errors: ’ Unexpected token < in JSON at position 0’ and ’ Server responded with an error. Authentication required’. Then when I try to click elsewhere in the admin, I am taken back to the login page.

I have uploads enabled and the files I am trying to upload are smaller than my defined upload limit.

Any advice on how to diagnose this?

It seems that users are somehow being logged out in the middle of file uploads. I’m not sure how to debug this, though. Does anyone have any advice on this front?

What hosting platform are you using? Could be that the session is getting lost somewhere, especially if there’s some load balancing at work.
Check the network requests… is the protocol and hostname the same as the one you’re logged into the admin with? (eg. vs

The hosting platform is Cloudways. To answer your questions,as near as I can tell, according to the Network tab, all the resources are all being delivered over https. My inkling was that it might have something to do with the way the sessions are handled on the server, but I’m not sure how to test that hypothesis.

Varnish is installed on the server. Could this have some adverse affect?

I wish I had more insight to offer, but I haven’t been able to pinpoint the cause of the problem, or even reliably reproduce it. File uploads were working fine for a couple months, then suddenly started causing this problem.

To be honest, I am not that familiar with Varnish or the configuration thereof. I could simply turn it off, but that seems suboptimal.

Would you mind expounding a bit on something, within Varnish Configuration, that may have an adverse affect - that is, if you can think of something?

Most definitely it could be related. Do you have control over that? If so, it would be worth going through the VCL carefully and making sure that it’s managing the sessions properly. If you don’t have access, it’s worth checking with the people who manage it to see if they can shed any light on what may have changed between when it worked last and now.

Does turning it off solve the problem? Best to check that first, since if it doesn’t then the issue doesn’t lie with Varnish :wink:

1 Like

It looks like turning off the Varnish Cache did the trick. I just looked at the Varnish Config that I am able to change. I can create rules for cookies or URLs.

In the Cloudways docs, it says this, “Excluding cookie such as $cookie_name (user_2545) would prevent the cookie strings caching and would allow them to work bypassing caches. This is used when cookies create different sessions and calls and are unique.”

Do you think an exclusion rule should be created for the admin section, or the user cookie, or both?

It’s probably just as well to create an exclusion for the entire admin area, rather than messing around trying to catch all the right cookies. You don’t really want any of the CMS pages being cached

I enabled Varnish, then I tried disabling the admin section with an exclusion for /admin/* but that didn’t work. Next, I added the PHPSESSID cookie to the Varnish exclusion list and that seemed to do the trick. This error has been haunting me for months. Thanks for the help!