Repository navigation
Sound #5218
SamarthKadam
started this conversation in
General
Sound
#5218
Replies: 1 comment
|
To download a sound file with a .mp4 extension from an Express server to the client side, you can use the following code on the server side: const express = require('express');
const app = express();
const fs = require('fs');
app.get('/download', (req, res) => {
const filePath = 'path/to/your/soundfile.mp4';
const fileName = 'your_soundfile.mp4';
res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
res.setHeader('Content-Type', 'audio/mpeg'); // Change to the appropriate audio format if necessary
const fileStream = fs.createReadStream(filePath);
fileStream.pipe(res);
});
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});On the client side, you can simply create a link or button that points to the server route to trigger the download: <!DOCTYPE html>
<html>
<head>
<title>Sound File Download</title>
</head>
<body>
<a href="http://your-express-server/download">Download Sound File</a>
</body>
</html>When the user clicks the link, the sound file will be downloaded to their device. Make sure to replace
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I need to download a file which is sound file. the sound file is hosted online with .mp4 extension. How can I download it in the client side
All reactions