diff --git a/app.js b/app.js
index ef03cd2..de7c5e1 100644
--- a/app.js
+++ b/app.js
@@ -47,11 +47,14 @@ export default ({ sharedPath: sharedPathIn, port, maxUploadSize, zipCompressionL
// NOTE: Must support non latin characters
app.post('/api/upload', bodyParser.json(), asyncHandler(async (req, res) => {
// console.log(req.headers)
+ const uploadDirPathIn = req.query.path || '/';
+
+ const uploadDirPath = await getFileAbsPath(uploadDirPathIn);
// parse a file upload
const form = Formidable({
keepExtensions: true,
- uploadDir: sharedPath,
+ uploadDir: uploadDirPath,
maxFileSize: maxUploadSize,
maxFields,
});
@@ -67,12 +70,12 @@ export default ({ sharedPath: sharedPathIn, port, maxUploadSize, zipCompressionL
const files = Array.isArray(filesIn) ? filesIn : [filesIn];
// console.log(JSON.stringify({ fields, files }, null, 2));
- console.log('Uploaded files:');
+ console.log('Uploaded files to', uploadDirPath);
files.forEach((f) => console.log(f.originalFilename, `(${f.size} bytes)`));
await pMap(files, async (file) => {
try {
- const targetPath = join(sharedPath, filenamify(file.originalFilename, { maxLength: 255 }));
+ const targetPath = join(uploadDirPath, filenamify(file.originalFilename, { maxLength: 255 }));
if (!(await pathExists(targetPath))) await fs.rename(file.filepath, targetPath); // to prevent overwrites
} catch (err2) {
console.error(`Failed to rename ${file.originalFilename}`, err2);
diff --git a/ezshare-frontend/src/App.jsx b/ezshare-frontend/src/App.jsx
index 917a6bc..90eaa0a 100644
--- a/ezshare-frontend/src/App.jsx
+++ b/ezshare-frontend/src/App.jsx
@@ -47,7 +47,7 @@ const Section = ({ children, style }) => (
);
-const Uploader = ({ onUploadSuccess }) => {
+const Uploader = ({ onUploadSuccess, cwd }) => {
const [uploadProgress, setUploadProgress] = useState();
const [uploadSpeed, setUploadSpeed] = useState();
@@ -77,7 +77,7 @@ const Uploader = ({ onUploadSuccess }) => {
if (dataLoaded && startTime) setUploadSpeed(dataLoaded / ((Date.now() - startTime) / 1000));
};
- await axios.post('/api/upload', data, { onUploadProgress });
+ await axios.post(`/api/upload?path=${encodeURIComponent(cwd)}`, data, { onUploadProgress });
Toast.fire({ icon: 'success', title: 'File(s) uploaded successfully' });
onUploadSuccess();
@@ -92,7 +92,7 @@ const Uploader = ({ onUploadSuccess }) => {
}
upload();
- }, [onUploadSuccess]);
+ }, [cwd, onUploadSuccess]);
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop });
@@ -288,7 +288,7 @@ const Browser = () => {