Workers API upload error

#1

All,

I’m having trouble uploading my Workers script via the CF Workers API. When pasting the same script into the sandbox, it works fine. No go here, though. :frowning:

curl -s -X PUT \
     -H "X-Auth-Email: EMAIL_REMOVED" \
     -H "X-Auth-Key: AUTH_KEY_REMOVED" \
     -H "Content-Type: application/javascript" \
     --data-binary "build/script.js" \
     -o "/tmp/deploy.sh.ejcLYT/output_script.js.7TVhf3" \
     "https://api.cloudflare.com/client/v4/zones/ZONE_ID_REMOVED/workers/script"

Which returns:

{
  "result": null,
  "success": false,
  "errors": [
    {
      "code": 10021,
      "message": "Uncaught ReferenceError: build is not defined\n  at line 1\n"
    }
  ],
  "messages": []
}

Any idea what I’m doing wrong?

Thanks,

Jason.

#2

Have you copied your code manually to see if throws an error?

#3

I just retried it. Apparently JS requires whitespace around =. After making that change in the sandbox, the script works fine.

So, I made the exact same change to script I upload and it poops the same error. Very frustrating.

Thanks,

Jason.

#4

There is a missing @ --data-binary

curl -s -X PUT \
     -H "X-Auth-Email: EMAIL_REMOVED" \
     -H "X-Auth-Key: AUTH_KEY_REMOVED" \
     -H "Content-Type: application/javascript" \
     --data-binary "@build/script.js" \
     -o "/tmp/deploy.sh.ejcLYT/output_script.js.7TVhf3" \
     "https://api.cloudflare.com/client/v4/zones/ZONE_ID_REMOVED/workers/script"
#5

Doh! You’re absolutely right. That was it. I made that one change and it now works perfectly.

Thanks!