[Released] File upload via Monday's SDK client side

I just wanted to update on my quest regarding file upload through the client side!

Monday.api() was unsuccessful, but I attempted to try again with a normal post request and I was met with a CORS problem. CORS issue when uploading file with API v2

I was still getting a CORS problem for /v2 and /v2/file endpoint, but I remembered a post saying /v2 was fixed so I figured I should give it a shot with a published build rather than a custom URL where my origin is https:…ngrok.io.

It works for /v2 endpoint with published build!!

  const onChange = async ({
    target: {
      validity,
      files: [file],
    },
  }) => {
    if (validity.valid) {
      const filename = file.name;
      const formData = new FormData();
      formData.append("variables[file]", file, filename );

      const noVariableQuery = `mutation addFile($file: File!) {add_file_to_update (update_id: thatupdateidugot, file: $file) {id}}`;
      formData.append("query", noVariableQuery )

      await fetch('https://api.monday.com/v2/', {
        method: "POST",
        body: formData,
        headers: {
          "Authorization": token
        }
      }).then((res) => res.json()).then((response) => console.log(response)).catch((err) => console.log(err))

    }
  };

Unfortunately this doesn’t work for /v2/file endpoint due to CORS and /v2/ is blocked as well from custom URLs still so that’s a bummer for testing.

3 Likes