简体   繁体   中英

Writing a file to disk then uploading to S3

I got some code working to download an MP3 file using request and then upload to S3 trouble is when it got up there the file was corrupt. So trying to download to disk first but a lot of fs commands don't have a great callback. Any help you could provide would be helpful - still learning and getting the hang of async concepts

parser.parseURL('https://bridgetown.podbean.com/feed.xml', function (err, feed) {
  request(feed.items[0].enclosure.url).pipe(audioFile).on('close', function () {
    console.log("downloadfinsihed")
    s3.upload({ Bucket: bucketName, Key: "testperm3.mp3", Body: "Audio.mp3" }, function (err, data) {
      transcribeservice.startTranscriptionJob({LanguageCode: "en-US", Media:{MediaFileUri: data.Location}, MediaFormat: "mp3", TranscriptionJobName: "testing"}, function (err, data){
                         //console.log(data);           
                });

          });
        });
      });

This could be a situation where using the promise-based async/await syntactic sugar might help to convert the callbacks to asynch versions.

Try something like this:

 parser.parseURL('https://bridgetown.podbean.com/ 
 feed.xml', async function (err, feed) {
    const res = await request(feed.items[0].enclosure.url).pipe(audioFile)

....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM