Skip to content

Instantly share code, notes, and snippets.

@NickFoden
Created January 31, 2021 17:24
Show Gist options
  • Save NickFoden/109bd073fcd7c540956468563a286d4c to your computer and use it in GitHub Desktop.
Save NickFoden/109bd073fcd7c540956468563a286d4c to your computer and use it in GitHub Desktop.
Stream Upload
// https://developers.cloudflare.com/stream/uploading-videos/upload-video-file
const uploadFile = async (e) => {
const body = new FormData();
body.append("file", e.currentTarget.files[0]);
//Tried without this next line body.append and with it
body.append("", "\\");
const result = await fetch(
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT/stream",
{
body,
headers: {
Authorization: "Bearer $TOKEN",
"Content-Type": "multipart/form-data",
},
method: "POST",
}
)
.then((R) => R.json())
.then((M) => M)
.catch((e) => {
console.error(e);
return e;
});
console.dir(result);
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment