Hi folks,
I have interesting issue.
When I run automation from editor, everything looks ok and file is uploaded to S3 (AWS s3, using upload promise).
When I run same script using action (custom button), workflow state is green, log seems ok, but the file is not uploaded.
Can someone tell me where could be the problem?
Thank you
Petr
async function getPromise(url: string, access_token: string, config:object){
console.log("Get upload promise")
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Content-Type", "application/json");
var body = {
instance: config.instance,
instance_key: config.instance_key
}
var requestOptions = {
method: "POST",
bearer: access_token,
headers: myHeaders,
body: JSON.stringify(body)
};
var resp = await doo.functions.request.custom(url, requestOptions);
console.log(resp);
return resp
}
async function s3upload(url: string, access_token: string, config: object, file: File){
console.log("Upload file to S3")
const promise = await getPromise(url, access_token, config)
console.log("Promise has been granted")
const s3url = promise.url
const myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
var data = new FormData()
data.append("key", promise.fields.key)
data.append("x-amz-algorithm", promise.fields["x-amz-algorithm"])
data.append("x-amz-credential", promise.fields["x-amz-credential"])
data.append("x-amz-date", promise.fields["x-amz-date"])
data.append("x-amz-security-token", promise.fields["x-amz-security-token"])
data.append("policy", promise.fields.policy)
data.append("x-amz-signature", promise.fields["x-amz-signature"])
data.append("file", file)
for (var pair of data.entries()) {
console.log(pair[0]+ ': ' + pair[1]);
}
var requestOptions = {
method: "POST",
headers: myHeaders,
mode: "no-cors",
body: data
};
var resp = await fetch(s3url, requestOptions)
.then(data => {
console.log(data);
})
.catch(e => {
console.log(e);
});
console.log(resp)
}