I am using ionic 3 platform for uploading a video file to vimeo api. I need to get binary data for video file and I am uploading using input type file element.
The code I have written is as follow
videoUploadBody(videoObj) {
const r = new FileReader();
r.onload = function(){
console.log("Binary data", r.result);
return r.result;
};
r.readAsArrayBuffer(videoObj);
}
This is the function that I need to call and it should return me video file in binary form. The function from where I am calling above function is as follow
uploadVideo(videoFile, createdVideo) : Observable<any> {
const bodyObj = this.compilerProvider.videoUploadBody(videoFile);
return this.http.patch<Observable<any>>(createdVideo.upload.upload_link, bodyObj, this.uploadReqOpts);
}
Here the bodyObj variable contains undefined, whereas I have console.log is videoUploadBody function gives me data in binary form.
I think there is some async or promise issue. What do I need to change to get back binary data in uploadVideo function?