Upload Video on amazon S3 with ionic


#1

Hi guys,
I need to upload a video on AWS.S3 platform. I don’t understand how do it. Could you please support me? I read several tutorial but it not works.

Thanks

Luca


#2

I was struggling with this same issue, but it can be accomplished easily with the

The trick is getting the URI of the image or video, open that path with the readAsArrayBuffer and then pass that result to the aws Storage put function with the correct type.

You can use the camera, video or whatever just as long as you get a mediafile (https://ionicframework.com/docs/native/media-capture/) then pass that mediafile to our upload function. Here’s my example,

upload(mediafile){
    var path = mediafile[0].fullPath;
    var filename = mediafile[0].name;
    var first = 'file:/' + path.substr(0,path.lastIndexOf('/')+1);
    this.file.readAsArrayBuffer(first,filename)
      .then( body => {
        Storage.put(this.userId + '/test.mov', body,{contentType : mediafile[0].type } )
          .then(() => {
            console.log('Video uploaded');
          })
          .catch(err => {
            console.log('Video uploaded' + JSON.stringify(err));
          });
      })
      .catch(err => console.log(err));
  }

#3

if possible provide full example …
Thanks