Closed mickeymond closed 7 months ago
@alireza12prom After forking the code, it was clear after my testing that joining the this.options.path and the objectName on Windows (where the API code is running) is the one creating the mess. I changed the code to below and it works on Windows and hopefully on Unix/Linux
private _getObjectPath(objectName: string) {
const { path } = this.options;
// return join(path || '/', objectName);
return `${path}/${objectName}`;
}
I have tried searching for a way to get path.join
to work on Windows like it does on Unix/Linux but to no avail so please advice and I am more than happy to raise a PR.
Hi @mickeymond
I reviewed your issue and you're right. I've searched and found something that can help to normalize unix-style paths (whether the OS is Windows or Linux). Also notice that the path
is undefined if the client doesn't specify it.
private _getObjectPath(objectName: string) {
const { path } = this.options;
return posix.join(`${path || '/'}/${objectName}`);
}
Please fix it and then make a PR. Thanks for contributing!
@alireza12prom Thank you very much for sharing.
After looking at the posix available in nodejs I am more compelled to just change only the join
to posix.join
in your existing implementation like below.
private _getObjectPath(objectName: string) {
const { path } = this.options;
// return join(path || '/', objectName); // Your implementation
return posix.join(path || '/', objectName); // Replacing **join** with **posix.join**
}
I just want to know if using the string interpolation like so return posix.join(`${path || '/'}/${objectName}`);
with the posix.join has any extra benefits.
PS: Your earlier implementation actually checks if the path is undefined and defaults to '/'.
Windows seems to use forward slashes leading to path not creating folders in the bucket like one would expect them to.
Upload Config Below
Console Log of
req.file