After server migration, Silverstripe 4 throwing error when trying to upload files

4

Question:

I just migrated a SS4 site to a new server. Now, when I try to upload an image, I get the message below. Here is one of the errors I’ve been seeing:

>
> 
> Server responded with an error. Authentication required
> 
> Unexpected token > in JSON at position

This is happening even though I have just authenticated as an Admin. I thought it was a permissions problem on the file system, but after looking further into it, that doesn’t seem to be the case.

The files do seem to upload, but the preview is not created and does not appear in the preview area. I can save the asset, but not with the “save” and “publish” buttons in the bottom right, I have to use the bulk actions to publish the files. Once I do this, the preview appears.

I’m receiving / have received these error in the console:

Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

(async)http://example.com/admin/assets/show/295/edit/307 400 (Bad Request)

GET http://example.com/admin/assets/show/295/edit/307 400 (Bad Request)

I’m also receiving an error message in the CMS, above the preview, that reads, “Your session has expired. Please re-submit the form.”

Today, in the console, I discovered that there is an error in the following ajax call, which is executed on the upload:
http://example.thing/Security/ping
Right before this call:
http://example.thing/admin/assets/api/createFile
which throws the 400 (Bad Request) error.

You might be able to see more about this error in the Network tab of your browser’s dev tools, by looking at the full response of those requests that gave a 400 response. The Unexpected token < in JSON at position 0 part implies that a html response was received when a JSON one was expected, so there might be a detailed error message there.

@JonoM ,

In the console, I am receiving this:

vendor.js?m=1530220188:1 Warning - the `printer` exports from `graphql-tag` will be removed in the next major version.
See https://github.com/apollographql/graphql-tag/issues/54 for more information.

(not sure if this has anything to do with it)

Followed by this:

GET http://178.128.xxx.xxx/assets/Wines/Brands/Aime-Boucher/Touraine-Sauvignon-Blanc/1893896a3d/logo__FitMaxWzkzMCwzMzZd.jpg 404 (Not Found)
Image (async)
i @ vendor.js?m=1530220188:1
dangerouslyReplaceNodeWithMarkup @ vendor.js?m=1530220188:1
_replaceNodeWithMarkup @ vendor.js?m=1530220188:1
_updateRenderedComponent @ vendor.js?m=1530220188:1
_performComponentUpdate @ vendor.js?m=1530220188:1
updateComponent @ vendor.js?m=1530220188:1
receiveComponent @ vendor.js?m=1530220188:1
receiveComponent @ vendor.js?m=1530220188:1
_updateRenderedComponent @ vendor.js?m=1530220188:1
_performComponentUpdate @ vendor.js?m=1530220188:1
updateComponent @ vendor.js?m=1530220188:1
performUpdateIfNecessary @ vendor.js?m=1530220188:1
performUpdateIfNecessary @ vendor.js?m=1530220188:1
s @ vendor.js?m=1530220188:1
perform @ vendor.js?m=1530220188:1
perform @ vendor.js?m=1530220188:1
perform @ vendor.js?m=1530220188:1
M @ vendor.js?m=1530220188:1
closeAll @ vendor.js?m=1530220188:1
perform @ vendor.js?m=1530220188:1
batchedUpdates @ vendor.js?m=1530220188:1
u @ vendor.js?m=1530220188:1
r @ vendor.js?m=1530220188:1
enqueueSetState @ vendor.js?m=1530220188:1
r.setState @ vendor.js?m=1530220188:1
s.handleChange @ vendor.js?m=1530220188:1
(anonymous) @ vendor.js?m=1530220188:1
i @ vendor.js?m=1530220188:1
(anonymous) @ vendor.js?m=1530220188:1
(anonymous) @ vendor.js?m=1530220188:1
(anonymous) @ vendor.js?m=1530220188:1
(anonymous) @ bundle.js?m=1530220187:1
Promise.then (async)
value @ bundle.js?m=1530220187:1
value @ bundle.js?m=1530220187:1
notifyAll @ vendor.js?m=1530220188:1
close @ vendor.js?m=1530220188:1
closeAll @ vendor.js?m=1530220188:1
perform @ vendor.js?m=1530220188:1
perform @ vendor.js?m=1530220188:1
perform @ vendor.js?m=1530220188:1
M @ vendor.js?m=1530220188:1
closeAll @ vendor.js?m=1530220188:1
perform @ vendor.js?m=1530220188:1
batchedUpdates @ vendor.js?m=1530220188:1
o @ vendor.js?m=1530220188:1
dispatchEvent @ vendor.js?m=1530220188:1

Hi @mckinselberg, the Console is just one part of the Dev tools in your browser and doesn’t give you a lot of information about http requests. If you click the Network tab you can get more information on the response from the server.

@jonom, i don’t see anything unusual in the network tab, though I’m not entirely sure what to look for.

To me, what seems to be happening is that in the middle of the upload, my session is being terminated. Not each time, but most times, the CMS logs me out and asks me to reauthenticate if I want to work with the just-uploaded files.

Try turning off mod security on the server and see if it still happens

@CW_Chong - mod_security is not turned on.

This problem has resolved on its own.
Some of the steps I’ve taken:

checked file paths and permissions

dev/build
dev/build?flush=1
dev/build?flush-all

edited php.ini
increased upload size
increased execution limit
increased memory limit
turned on error reporting

inspected console and network stack trace for clues

turned off varnish cache
restarted php, apache, etc…

problem resolved after testing multiple file uploads, edits, deletes, etc…

turned off error reporting
turn on varnish cache