I want to use Shopify api. And I want to upload video with this API. So official document like that:
https://shopify.dev/api/examples/product-media#videos-3d-models-post-request
So, I created an axios config and I tried to send request.
My code snipped like that:
let fd = new FormData();
fd.append("bucket", bucket);
fd.append("key", key);
fd.append("policy", policy);
fd.append("cache-control", cacheControl);
fd.append("x-amz-signature", xAmzSignature);
fd.append("x-amz-algorithm", xAmzAlgorithm);
fd.append("x-amz-date", xAmzDate);
fd.append("file", fs.createReadStream('./milk.mp4'));
const config: AxiosRequestConfig = {
url: "https://shopify-video-production-core-originals.s3.amazonaws.com/",
data: fd,
method: "POST",
headers: { "Content-Type": "multipart/form-data" }
}
try {
const videoPost = await axios(config);
}
catch (err) {
console.log(err)
}
So, I getting an error like that:
....
....
[Symbol(kOutHeaders)]: [Object: null prototype]
},
data: '<?xml version="1.0" encoding="UTF-8"?>n' +
'<Error><Code>MalformedPOSTRequest</Code><Message>The body of your POST request is not well-formed multipart/form-data.</Message><RequestId>184VT99AXG4J6FWW</RequestId><HostId>1IBK7dCgApORGZnaGxS/n22Ftgw0fRBW1EnMuhFpEPek5R3iwsa2T9MH2q8A31l1AU9lhAb2WYA=</HostId></Error>'
},
isAxiosError: true,
toJSON: [Function: toJSON]
}
Why Im getting this error? How can I solve this? Please Help
2
Answers
As the documentation says, there are two versions for the formdata syntax.
Change the code as mentioned below:
to
Here is the Solution