How to Upload a .wav File on S3

Record audio and upload it to AWS S3

  1. Recording of audio.
  2. Uploading the file to S3 using AWS-SDK
  1. Recording of sound using mic-recorder-to-mp3 npm
          npx create-react-app audiorecord        
          npm install --salve mic-recorder-to-mp3                  
          const audioRecorder = new MicRecorder({ bitRate: 128 });        
          navigator.getUserMedia({ audio: truthful ,video:false},          .and then() => {                      console.log('Permission Granted');                      this.setState({ isblocked: false });
},
.catch() => { console.log('Permission Denied'); this.setState({ isblocked: truthful }) }, );
          <push onClick={this.beginning} disabled={this.land.isrecording}                         blazon="button">Start</push button>          <push onClick={this.cease} blazon="push">Stop</button>        
          kickoff = () => {          if(this.state.isblocked){          console.log('permission Denied');          }else{          audioRecorder.start()          .then(()=>{          this.setState({          isrecording:true          });          }).catch((eastward)=> console.log(e));          }          };          cease = () => {          audioRecorder.stop()          .getMp3()          .then(([buffer,hulk])=>{          const blobUrl = URL.createObjectURL(hulk)          this.setState({blobUrl,isrecording:fake});          var d = new Engagement();          var file = new File([blob],d.valueOf(),{ type:"sound/wav" })          console.log(file);          this.handleaudiofile(file);          }).catch((e)=>panel.log('We could not remember your message'));          };        

https://{Saucepan NAME}.s3.{REGION}.amazonaws.com/{FILENAME}.

          handleaudiofile(ev){          permit file = ev;          permit fileName = ev.name;          let fileType = ev.type;          axios.post("http://localhost:5000/sign_s3",{          fileName : fileName, //parameter 1          fileType : fileType  //parameter 2          })          .and so(response => {          var returnData = response.information.information.returnData;          var signedRequest = returnData.signedRequest;          var url = returnData.url;          var options = {          headers: {          'Content-Type': fileType,          }          };          axios.put(signedRequest,file,options)          .then(issue => {          this.setState({sound: url,          },()=> console.log(this.country.audio))          alert("audio uploaded")})          .catch(error => {          alert("ERROR " + JSON.stringify(error));          })          })          .catch(fault => {          alarm(JSON.stringify(fault));          })          }        
          var aws = crave('aws-sdk');          crave('dotenv').config(); // Configure dotenv to load in the .env file          // Configure aws with your accessKeyId and your secretAccessKey          aws.config.update({          region: 'us-due east-2', // Put your aws region here          accessKeyId: process.env.AWSAccessKeyId,          secretAccessKey: process.env.AWSSecretKey          })          const S3_BUCKET = process.env.Bucket          // Now lets export this office then we can call it from somewhere else          exports.sign_s3 = (req,res) => {          const s3 = new aws.S3();  // Create a new instance of S3          const fileName = req.torso.fileName;          const fileType = req.body.fileType;          // Fix the payload of what we are sending to the S3 api          const s3Params = {          Bucket: S3_BUCKET,          Cardinal: fileName,          Expires: 3000,          ContentType: fileType,          ACL: 'public-read'          };          // Brand a request to the S3 API to become a signed URL which nosotros tin can apply to upload our file          s3.getSignedUrl('putObject', s3Params, (err, data) => {          if(err){          panel.log(err);          res.json({error: err})          }          // Data payload of what we are sending back, the url of the signedRequest and a URL where we tin can access the content after its saved.          const returnData = {          signedRequest: data,          url: `https://${S3_BUCKET}.s3.amazonaws.com/${fileName}`          };          res.json({data:{returnData}});          });          }        

phillipsnestandmand.blogspot.com

Source: https://medium.com/@sanjana01999/record-audio-and-upload-it-to-aws-s3-409f5e620805

0 Response to "How to Upload a .wav File on S3"

ارسال یک نظر

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel