Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folder upload #287

Open
Spiderjockey02 opened this issue Sep 13, 2021 · 1 comment
Open

Folder upload #287

Spiderjockey02 opened this issue Sep 13, 2021 · 1 comment

Comments

@Spiderjockey02
Copy link

Spiderjockey02 commented Sep 13, 2021

When I upload a folder, it will only get the actual files within the folder instead of the folder aswell? Is it possible to get the folder and then inside that the files?

router file:

// upload files to user's account
router.post('/upload', ensureAuthenticated, (req, res) => {
	if (!req.files || Object.keys(req.files).length === 0) {
		return res.status(400).send('No files were uploaded.');
	}

	// Find where to place the file
	const sampleFile = req.files.sampleFile;
	console.log(sampleFile);
	const path = req.body['path'];
	const directPath = path.split('/').slice(2, path.length).join('/');
	const newPath = location + req.user._id + '/' + directPath + '/' + sampleFile.name;

	// save file
	sampleFile.mv(newPath, function(err) {
		if (err) return res.status(500).send(err);
		res.redirect('/files/' + directPath);
	});
});

webpage file (.ejs):

<form action="/files/upload" method="post" encType="multipart/form-data" ref='uploadForm' id='uploadForm' >
    <label class="dropdown-item" type="button" id="fileHover">
        Files<input type="file" hidden name="sampleFile" onChange="javascript:document.getElementById('imagefile').click();" />
    </label>
    <input type="hidden" value="<%= path%>" name="path">
    <label class="dropdown-item" type="button" id="fileHover">
         Folders<input type="file" hidden name="sampleFile" webkitdirectory mozdirectory onChange="javascript:document.getElementById('imagefile').click();" />
    </label>
    <button type="submit" style="display:none;" id="imagefile"></button>
 </form>
@BluDood
Copy link

BluDood commented Oct 6, 2022

+1

EDIT: Seems like providing the preservePath: true option keeps the path in the filename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants