-1

I want to know how to download the files to aws-s3 through heroku, and dosen't use the web page.

I'm using wget in Nodejs to download audio files, and wanting to re-encoding them by ffmpeg. Though I have to store the file first, but heroku doesn't provide the space to store. Then I find the way that heroku can connect with aws-s3, however the sample code is the page for user to upload, and I'm just want to using codes.

This is the code that haven't connected with s3 yet.

  const wget = spawn('wget',['-O', 'upload_audio/'+ sender_psid +'.aac', audioUrl]);
  //spit stdout to screen
  wget.stdout.on('data', function (data) { process.stdout.write(data.toString()); });
  // //spit stderr to screen
  wget.stderr.on('data', function (data) { process.stdout.write(data.toString()); });

  wget.on('close', function (code) {

    console.log(process.env.PATH);
    const ffmpeg = spawn('ffmpeg',['-i', 'upload_audio/'+ sender_psid +'.aac', '-ar', '16000', 'upload_audio/'+ sender_psid +'.wav', '-y']);

...

});

And it comes the error:

upload_audio/1847432728691358.aac: No such file or directory
...
Error: ENOENT: no such file or directory, open 'upload_audio/1847432728691358.wav'

How can I solve the problem? Could anyone give some suggest plz? Maybe won't use s3 can get it?

  • Is this a catch question? Isn't the answer kinda obvious? `No such file or directory` - the error is pretty self explaining, isn't it or am I missing something? – Beru Jul 22 '19 at 05:47
  • Hello, thanks for your comment. Because this is running on Heroku, no matter I create the folder, it can't work. – Aster Lin Jul 22 '19 at 05:52
  • Well then, if you create your folder but your download fails, I assume your creation seems to be flawed. – Beru Jul 22 '19 at 05:55
  • 1
    I think this is because heroku doesn't provide the space to store files. Now I am going to try to connnect with aws-s3 space, but I can't find any sample code. – Aster Lin Jul 22 '19 at 06:01

1 Answers1

1

I don't recommend using S3 until you've tried the NodeJS Static Files API. On the server, that looks like this:

app.use(express.static(path.join(__dirname, 'my_audio_files_folder')));

More on NodeJS's Static Files API available here.

AWS S3 seems to be adding unneeded complexity, but if you have your heart set on it, have a look at this thread.