Why am I getting a 503 error when uploading a video to a store?

Why am I getting a 503 error when uploading a video to a store?

cormacncheese
Shopify Partner
11 0 0

I'm following the instructions in step 1 here to upload a video to a shop owner's store.  I was able to get the parameters back from `stagedUploadsCreate` but when posting the file using form data I receive a `Service Unavailable` status 503 error.

 

Also wondering once I successfully get the video posted, will the `resourceUrl` be publicly available for the store owner to display the video in their storefront?

 

Here is the code I'm using to create and submit the form data:

 

 

const response = await fetch(
    `https://${shop}/admin/api/2021-10/graphql.json`,
    {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "X-Shopify-Access-Token": accessToken,
    },
    body: prepareVideoToUpload,
    }
);

const responseJson = await response.json();

const target = responseJson.data.stagedUploadsCreate.stagedTargets;
const parameters = target[0].parameters;
const resourceUrl = target[0].resourceUrl;

const form = new FormData();
form.append(parameters[0].name, parameters[0].value);
form.append(parameters[1].name, parameters[1].value);
form.append(parameters[2].name, parameters[2].value);
form.append(parameters[3].name, parameters[3].value);
form.append(
  "file",
  fs.readFileSync(`files/${fileData.name}`),
  `files/${fileData.name}`
);

// upload request
await axios
    .post(target[0].url, {
        body: form,
    })
    .then((res) => {
        console.log("upload res: ", res);
    })
    .catch((e) => {
        console.log("upload e: ", e);
    });

 

 

Reply 1 (1)

cormacncheese
Shopify Partner
11 0 0

I must have had wrong syntax somewhere, got the request to go through using the following code below.

 

However this now returns a 403 Forbidden error

 

 

const form = new FormData();
form.append(parameters[0].name, parameters[0].value);
form.append(parameters[1].name, parameters[1].value);
form.append(parameters[2].name, parameters[2].value);
form.append(parameters[3].name, parameters[3].value);
form.append(
  "file",
  fs.readFileSync(`files/${fileData.name}`),
  `files/${fileData.name}`
);

// upload request
await axios(target[0].url, form, {
    headers: {
    ...form.getHeaders(),
    },
})
.then((res) => {
    console.log("upload res: ", res);
})
.catch((e) => {
    console.log("upload e: ", e.response);
});