Possible access a server-created file in /tmp from client?

I’m new to node.js and hyperdev, and all’s going great except…

  1. I’m generating a small file in /tmp/file.mp3 successfully, but referring to it as gives a 404. I tried app.use(express.static('tmp)); but that doesn’t help; I seem to be able to refer to the file from server.js to create it, read it, etc., but can’t find a way to access from a client html page.

  2. Instead I refer to it as for which I’ve created an endpoint:

app.get("/i_stream", function (request, response) {
var stat = fs.statSync(fnameStream);
response.setHeader(‘Content-Type’, ‘audio/mpeg’);
response.setHeader(‘Content-Length’, stat.size);
var readStream = fs.createReadStream(fnameStream);
readStream.pipe(response);
});

and that works perfectly in IE 11, but in Chrome/Win and Chrome/Mac it plays through to the end, but the audio player seconds counter stops at 4 seconds and also stops emitting events after that point (the file is 8 seconds long). Also, while the mp3 files generated play fine in various players, there’s the above Chrome error, and also the audio file won’t play at all on iOS browser and Android 7 tablet Chrome browser, but it does play on Android Galaxy S7 phone Chrome browser.

I also tried jPlayer instead of native player and that too stops at 4 seconds using “/i_stream” endpoint.

I’m wondering if I run in plain node.js, w/o Hyperdev, and I could create the file in “public” and use “public” and then see the file from the client, that would help?

Sorry for the lengthy description, but I very much appreciate any help, and apologize for all newbieness!

Thanks,

Larry

Your root folder for serving files is /app/src, whereas tmp is at /tmp, so won’t be accessible from a client file without a route (e.g. https://hyperdev.com/#!/project/round-bite). Data in /tmp is cleared after 15 mins when the container gets destroyed/replaced, but should be accessible until then. But yes, creating the project locally and seeing if you encounter similar issues would at least determine whether it’s a HyperDev issue or not. If it is, then please provide a project URL, and I can look into this some more for you.

1 Like

Thanks, @Gareth, that did the trick; I had made a mistake before with sendFile() but that’s what I needed; much appreciated. I haven’t yet re-implemented locally to see if my /i_stream route as shown would work differently than in hyperdev, but if I do and and it does, I’ll reply.

Great job with HyperDev!

1 Like