Cloudflare Stream
A minimalistic node.js package for easily uploading videos to Cloudflare Stream.
Getting Started
Let's start off by installing the package via NPM.
npm i cloudflare-stream
Once you've done that, you're going to want to create an instance of a CloudflareStream with your credentials.
; const uploader = email: 'sam@example.com' // cloudflare email address key: 'c23864bc3ada9bf9c937810f62bb69a4e90b0' // cloudflare api key;
Now that you've made an instance, you're going to want to upload your video to your zone. Let's create an upload with your upload options.
const upload = uploader;
The upload method returns an EventEmitter which has three events (progress, success, error).
Let's create some logs from your upload events.
upload; upload; upload;
API Documentation
CloudflareStream
constructor(credentials)
credentials
credentials.email
An email
is always required, it should be the email address which you use to sign in with Cloudflare.
credentials.key
A key
is always required, it should be the API Key which matches the email address which you use to sign in with Cloudflare.
credentials.zone
If a zone
is not set in the uploadOptions
of an instance method, then a zone
is required in the credentials
.
A zone
must be a valid Cloudflare DNS Zone which is accessable using the specified email address and API key.
upload(uploadOptions)
Returns an EventEmitter with three events (progress, success, error).
uploadOptions
uploadOptions.zone
If a zone
has not been set in the constructor, then a zone
is required in the uploadOptions
.
A zone
must be a valid Cloudflare DNS Zone which is accessable using the specified email address and API key.
If a zone
has already been set in the constructor, this value will overwrite it.
uploadOptions.path
If a buffer
has not been set in the uploadOptions
, then a path
is required.
A path
must be a string pointing to a video file on the local filesystem.
It can be either an absolute path or a path relative to the node.js process (process.cwd()
).
uploadOptions.zone
If a path
has not been set in the uploadOptions
, then a buffer
is required.
A buffer
must be a valid node.js Buffer.
Upload Events
uploadEvent.progress(message)
Emitted when a chunk has been successfully uploaded.
Example output:
uploaded: 23592 total: 65536 percentage: 3599
uploadEvent.success(message)
Emitted when the upload has successfully completed.
Example output:
"result": "uid": "dd5d531a12de0c724bd1275a3b2bc9c6" "thumbnail": "https://cloudflarestream.com/dd5d531a12de0c724bd1275a3b2bc9c6/thumbnails/thumb.png" "readyToStream": false "status": "state": "inprogress" "step": "encoding" "pctComplete": "78.18" "meta": {} "labels": "created": "2018-01-01T01:00:00.474936Z" "modified": "2018-01-01T01:02:21.076571Z" "size": 62335189 "preview": "https://watch.cloudflarestream.com/dd5d531a12de0c724bd1275a3b2bc9c6" "success": true "errors": "messages":
uploadEvent.error(message)
Emitted whenever an error has occured.
Example output:
message: 'Invalid Cloudflare Credentials'