I have been googling constantly and can't seem to find an answer for this. My apologies if it's a noob question as I am still extremely new to Docker.
Scenario:
I have a dockerized web app with a NodeJS backend. On the website, I need to be able to upload files and store the path to them in the database (MSSql Database container). When I upload files using multiparty on the Node end, it gives it the temp path for files. On Windows, its ...../AppData/Local/Temp/.... On Linux, it looks to be /tmp/... Then, I use this path as a link to open the file from a different page. On Windows, running the app locally (no dockerizing), I can access the file (excluding Chrome's security features that prevent the download). However, on Linux and dockerized, there is no file. I will attach my file uploading code at the bottom.
I know that docker containers do not talk to the host's file system like a normal web application. My file isn't being stored in the /tmp folder as I've already checked there. My guess is that it is somehow storing it within the container.
My confusion lies with how to store these files. Volumes seem to be for loading files into containers and storage drivers don't seem to be something you can mess with other than to configure them (I am using overlay2 if it matters). How do I store the uploaded files within my container so that I can store their path and access them again later?
var app = express();
app.post("/api/files", function(req, res) {
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
var dict = files.Contents[0];
console.log(dict);
var query = "EXECUTE CTF.dbo.CTF_CreateFilesSp " + fields.ID + ", '" + dict["originalFilename"] + "', '" + dict["path"] + "'";
executeQuery(query, res);
});
});
UPDATE: I was able to get a volume/bind mount set up for my container using:
volumes:
- /var/opt/tmp:/var/opt/tmp
and I updated my parsing method to this:
app.post("/api/files", function(req, res) {
var form = new multiparty.Form();
var target_path = '';
form.on('file', function(name, file) {
var tmp_path = file.path;
target_path = '/var/opt/tmp/' + file.originalFilename;
fs.copyFile(tmp_path, target_path, function(err) {
if (err) console.error(err.stack);
else console.log(target_path);
})
});
form.parse(req, function(err, fields, files) {
var dict = files.Contents[0];
var query = "EXECUTE CTF.dbo.CTF_CreateFilesSp " + fields.ID + ", '" + dict["originalFilename"] + "', '" + target_path + "'";
executeQuery(query, res);
});
});
When I upload the file, I do see a copy of this show up in the host's directory as expected. However, when I click the link to the file on an html page, using the full path /var/opt/tmp/FILENAME, it says cannot GET /var/opt/tmp/FILENAME. I'm sure this has to do with incorrect permissions or href in my html, but I'm not sure. I'm very new to web development.
How do I get the link on an html page to download this file from the directory? Please let me know if this is out of the scope of the original question and I'll make a new one.