Understanding Active Storage Direct Upload errors: `Error storing "File_1.jpeg". Status: 0`

Viewed 924

Our app recently switched to direct uploads to S3 via Rails Active Storage (introduced in Rails 5.2) For the most part, it's working alright, but we're noticing that an error gets thrown around 2% of the time.

We've seen the following so far:

Status 0 (predominantly with Safari/ Mobile Safari): Error storing "File_1.jpeg". Status: 0

Status 403: Error storing "File_1.jpeg". Status: 403

Error reading: Error reading "File_1.jpeg".

I imagine the last error relates to the file itself being invalid or corrupt. However, we're unsure what could be resulting in the first two errors. Searching around, I notice posts mentioning CORS settings being incorrect. However, we've made some configuration changes before on S3, and I would also think that if it was a CORS issue, we'd see failure a lot more frequently. This is what our CORS setting is:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
    <AllowedOrigin>https://app.ourapp.com</AllowedOrigin>
    <AllowedMethod>PUT</AllowedMethod>
    <MaxAgeSeconds>3600</MaxAgeSeconds>
    <AllowedHeader>Origin</AllowedHeader>
    <AllowedHeader>Content-Type</AllowedHeader>
    <AllowedHeader>Content-MD5</AllowedHeader>
    <AllowedHeader>Content-Disposition</AllowedHeader>
</CORSRule>
</CORSConfiguration>

We noticed in one multi-upload, that a user was able to upload 12 files successfully to active storage, but 1 error-ed out with status 0. The file itself wasn't corrupt or anything.

Any clue what could be causing direct upload flakiness sometimes?

2 Answers

The following worked for me:

[
    {
        "AllowedHeaders": [
            "Authorization"
        ],
        "AllowedMethods": [
            "GET"
        ],
        "AllowedOrigins": [
            "https://example.com"
        ],
        "ExposeHeaders": [],
        "MaxAgeSeconds": 3000
    },
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "PUT"
        ],
        "AllowedOrigins": [
            "https://example.com"
        ],
        "ExposeHeaders": []
    }
]

Got it from here.

Error storing "File_1.jpeg". Status: 0

I have seen this error occur for our users when there is a Data Loss Prevention (DLP) tool in place, which prevents sensitive files from leaving their network. If possible, have the user's IT team check their configuration to allow uploading such files.

Related