Ionic convert Video URI to File object for upload to Firebase
up vote
0
down vote
favorite
I want to convert video path URI to file object to Upload to Filebase storage. But after I selected video and call
window.resolveLocalFileSystemURL(...)
it's never alert File and uploadToFirebase() not call. So, I don't know how to do it.
doGetPicture()
// TODO:
// get picture from camera
const options: CameraOptions =
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
mediaType: this.camera.MediaType.VIDEO,
this.camera.getPicture(options).then((_imagePath) =>
alert('got image path ' + _imagePath);
window.resolveLocalFileSystemURL(_imagePath, function (fileEntry)
fileEntry.file(function (file)
alert('got file! '+file);
console.log('File__++ ', file);
);
);
);
uploadToFirebase(file)
// Create the file metadata
var metadata =
contentType: 'video/mp4'
;
// Upload file and metadata to the object 'videos/test.mp4'
this.fbRef.child('videos/' + file.name).put(file, metadata);
Thank you
PS. I'm using Ionic v.4
typescript firebase ionic-framework ionic3
add a comment |
up vote
0
down vote
favorite
I want to convert video path URI to file object to Upload to Filebase storage. But after I selected video and call
window.resolveLocalFileSystemURL(...)
it's never alert File and uploadToFirebase() not call. So, I don't know how to do it.
doGetPicture()
// TODO:
// get picture from camera
const options: CameraOptions =
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
mediaType: this.camera.MediaType.VIDEO,
this.camera.getPicture(options).then((_imagePath) =>
alert('got image path ' + _imagePath);
window.resolveLocalFileSystemURL(_imagePath, function (fileEntry)
fileEntry.file(function (file)
alert('got file! '+file);
console.log('File__++ ', file);
);
);
);
uploadToFirebase(file)
// Create the file metadata
var metadata =
contentType: 'video/mp4'
;
// Upload file and metadata to the object 'videos/test.mp4'
this.fbRef.child('videos/' + file.name).put(file, metadata);
Thank you
PS. I'm using Ionic v.4
typescript firebase ionic-framework ionic3
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to convert video path URI to file object to Upload to Filebase storage. But after I selected video and call
window.resolveLocalFileSystemURL(...)
it's never alert File and uploadToFirebase() not call. So, I don't know how to do it.
doGetPicture()
// TODO:
// get picture from camera
const options: CameraOptions =
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
mediaType: this.camera.MediaType.VIDEO,
this.camera.getPicture(options).then((_imagePath) =>
alert('got image path ' + _imagePath);
window.resolveLocalFileSystemURL(_imagePath, function (fileEntry)
fileEntry.file(function (file)
alert('got file! '+file);
console.log('File__++ ', file);
);
);
);
uploadToFirebase(file)
// Create the file metadata
var metadata =
contentType: 'video/mp4'
;
// Upload file and metadata to the object 'videos/test.mp4'
this.fbRef.child('videos/' + file.name).put(file, metadata);
Thank you
PS. I'm using Ionic v.4
typescript firebase ionic-framework ionic3
I want to convert video path URI to file object to Upload to Filebase storage. But after I selected video and call
window.resolveLocalFileSystemURL(...)
it's never alert File and uploadToFirebase() not call. So, I don't know how to do it.
doGetPicture()
// TODO:
// get picture from camera
const options: CameraOptions =
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
mediaType: this.camera.MediaType.VIDEO,
this.camera.getPicture(options).then((_imagePath) =>
alert('got image path ' + _imagePath);
window.resolveLocalFileSystemURL(_imagePath, function (fileEntry)
fileEntry.file(function (file)
alert('got file! '+file);
console.log('File__++ ', file);
);
);
);
uploadToFirebase(file)
// Create the file metadata
var metadata =
contentType: 'video/mp4'
;
// Upload file and metadata to the object 'videos/test.mp4'
this.fbRef.child('videos/' + file.name).put(file, metadata);
Thank you
PS. I'm using Ionic v.4
typescript firebase ionic-framework ionic3
typescript firebase ionic-framework ionic3
asked Nov 10 at 15:17
Ittiwut Wongsawat
63
63
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You could use ionic-native MediaCapture & File Plugins and record the video like this:
recordVid() {
let options: CaptureVideoOptions = limit: 1, duration: 5
this.mediaCap.captureVideo(options).then((data: MediaFile) =>
let capturedVid = data[0];
let localVideoPath = capturedVid.fullpath;
let directoryPath = localVideoPath.substr(0, localVideoPath.lastIndexOf('/'));
let fileName = localVideoPath.substr(localVideoPath.lastIndexOf('/') + 1);
this.file.readAsArrayBuffer(directoryPath, fileName).then((result) =>
console.log(result);
let blob = new Blob([result], type: "video/mp4" );
//then upload the blob to firebase storage
this.uploadToFirebase(blob);
);
//catch errors here and maybe add a function to play video in frontend
The UploadTask itself is described here:
Upload Video Blob to firebase
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You could use ionic-native MediaCapture & File Plugins and record the video like this:
recordVid() {
let options: CaptureVideoOptions = limit: 1, duration: 5
this.mediaCap.captureVideo(options).then((data: MediaFile) =>
let capturedVid = data[0];
let localVideoPath = capturedVid.fullpath;
let directoryPath = localVideoPath.substr(0, localVideoPath.lastIndexOf('/'));
let fileName = localVideoPath.substr(localVideoPath.lastIndexOf('/') + 1);
this.file.readAsArrayBuffer(directoryPath, fileName).then((result) =>
console.log(result);
let blob = new Blob([result], type: "video/mp4" );
//then upload the blob to firebase storage
this.uploadToFirebase(blob);
);
//catch errors here and maybe add a function to play video in frontend
The UploadTask itself is described here:
Upload Video Blob to firebase
add a comment |
up vote
0
down vote
You could use ionic-native MediaCapture & File Plugins and record the video like this:
recordVid() {
let options: CaptureVideoOptions = limit: 1, duration: 5
this.mediaCap.captureVideo(options).then((data: MediaFile) =>
let capturedVid = data[0];
let localVideoPath = capturedVid.fullpath;
let directoryPath = localVideoPath.substr(0, localVideoPath.lastIndexOf('/'));
let fileName = localVideoPath.substr(localVideoPath.lastIndexOf('/') + 1);
this.file.readAsArrayBuffer(directoryPath, fileName).then((result) =>
console.log(result);
let blob = new Blob([result], type: "video/mp4" );
//then upload the blob to firebase storage
this.uploadToFirebase(blob);
);
//catch errors here and maybe add a function to play video in frontend
The UploadTask itself is described here:
Upload Video Blob to firebase
add a comment |
up vote
0
down vote
up vote
0
down vote
You could use ionic-native MediaCapture & File Plugins and record the video like this:
recordVid() {
let options: CaptureVideoOptions = limit: 1, duration: 5
this.mediaCap.captureVideo(options).then((data: MediaFile) =>
let capturedVid = data[0];
let localVideoPath = capturedVid.fullpath;
let directoryPath = localVideoPath.substr(0, localVideoPath.lastIndexOf('/'));
let fileName = localVideoPath.substr(localVideoPath.lastIndexOf('/') + 1);
this.file.readAsArrayBuffer(directoryPath, fileName).then((result) =>
console.log(result);
let blob = new Blob([result], type: "video/mp4" );
//then upload the blob to firebase storage
this.uploadToFirebase(blob);
);
//catch errors here and maybe add a function to play video in frontend
The UploadTask itself is described here:
Upload Video Blob to firebase
You could use ionic-native MediaCapture & File Plugins and record the video like this:
recordVid() {
let options: CaptureVideoOptions = limit: 1, duration: 5
this.mediaCap.captureVideo(options).then((data: MediaFile) =>
let capturedVid = data[0];
let localVideoPath = capturedVid.fullpath;
let directoryPath = localVideoPath.substr(0, localVideoPath.lastIndexOf('/'));
let fileName = localVideoPath.substr(localVideoPath.lastIndexOf('/') + 1);
this.file.readAsArrayBuffer(directoryPath, fileName).then((result) =>
console.log(result);
let blob = new Blob([result], type: "video/mp4" );
//then upload the blob to firebase storage
this.uploadToFirebase(blob);
);
//catch errors here and maybe add a function to play video in frontend
The UploadTask itself is described here:
Upload Video Blob to firebase
answered Nov 26 at 15:44
Mind R
13
13
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240333%2fionic-convert-video-uri-to-file-object-for-upload-to-firebase%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown