Open jaseew01 opened 9 years ago
I'm thinking these, which are essentially one way:
-Another option would be to create file on harddrive, and send that file off -would return redirect to location of file -Look at expressjs middleware serve-static -express.static -to find this, go to express suite, guide, middleware
I looked at this, just to make sure that I am understanding it correctly, whenever I send a file off to the browser, express.static will simply populate certain header fields that get specified in the options argument correct?
and it does this only for files served from the root folder.
express.static sets things up so that when the browser asks for certain resources, they are accessed as files from a specific root folder on the disc, rather than you having to manually create requests. You should be able to tell it to monitor all requests that start with '/download'. So the first test that you have this working would be that you will have established a link between the '/download/...' requests and files/subfolders in a "download" folder, and if you put in the location bar a URL '.../download/afilename' it would serve as a response the file with name 'afilename' in the 'download' folder.
The next step would be to change your server's code, so that when the user asks for '/file/thefileid/download', a file with an appropriate name is created in the download folder, and you send back a redirect reply to a '/download/filename' address. The browser will then make a followup request to that address, which will be handled by express.static.
Once that is working, you need to set up a periodic method that will monitor the download folder, looking for "out-of-date" files and removing them.
Okay, got it.
does fs.writeFile(...) not create a file if it isn't already created?
It should create it. But of course your code will not be able to see that until the callback, because it is asynchronous.
My mistake, it does create the file, I was just creating it in the wrong spot. So now, I have the redirect inside of the writeFile(...) callback and the page is still getting redirected before the file actually exists.
So in the callback, what happens if you try to look for the file directly? Commit what you have and point me to where I should look.
Okay, so it does exist, I can read the content of the file on the hard drive from within the callback. Here, I'll commit real quick, maybe I'm just redirecting incorrectly or something.
I accidentally committed to Issue 13
Okay the first problem I encountered was a database error. Is your code creating the database if it doesn't already exist?
I think your redirect should not have the '/file' in front, it should start with '/downloads'
No, it just assumes that the database is already created, I will have to take care of that. The filecollection database should've been on this repository though.
Okay, so my redirect now looks like this:
res.redirect('/file/'+filename);
it still doesn't seem to be working.
Not '/file'!!! '/downloads' is what you want. You are redirecting them to a "downloads" resource, not a "file" resource.
I do see a fileCollection file on my comp, I wonder why it's not being accessed. Perhaps something wrong with the database program on my comp, I'll try to dig deeper.
Sorry, that is what I currently have, I just didn't type it all. So this is what I currently have: res.redirect('/file/downloads/'+filename);
No you should NOT have the '/file' in the front!!! It should start from the '/downloads'. Only downloads, no file in front.
Sorry, fixed it, the browser is still showing me the same message: Cannot GET /downloadsDocument3.txt
Cannot GET /downloads/Document3.txt
Okay, now shouldn't that have been: /downloads/Document3.txt
, i.e. with a slash between downloads and the filename?
Yes, I am full of typos today, that is what I have on my server.
Okay, I think you'll have to try to find what part of your code is receiving that request, see how far it makes it before it errors like that. Are you sure you are using express.static
properly? Have a look at:
http://blog.modulus.io/nodejs-and-express-static-content
The way I see it you need two tell it two things:
My guess is that as you have it now, a request to '/Document3.txt', without the /downloads in front, will succeed. Read that article to get the correct syntax.
Okay, I will read over it all again, thanks for the help
Below are the notes I have from our last meeting. I have looked into each option, and just wanted to get your opinion. I guess I would just like to know which one you thought would be the most appropriate to implement.
-Content-Disposition header for sending filename over http? -Or set Content-Type header to multipart/form-data and use the boundary to relay the filname through other headers -Also Look at HTTP_Definitive_Guide to put random info into headers. -Another option would be to create file on harddrive, and send that file off -would return redirect to location of file -Look at expressjs middleware serve-static -express.static -to find this, go to express suite, guide, middleware