hnrch02 / multer-ftp

FTP storage engine for multer
MIT License
7 stars 3 forks source link

Basepath converting forward slashes to backward slashes #1

Open alexhans1 opened 7 years ago

alexhans1 commented 7 years ago

Hey Folks,

I stumbled upon an issue while uploading file to my ftp location.

I'm using the following as my basepath: basepath: '/public_html/BDUDBdev/userpics/',

However the file is uploaded to the base directory of my ftp server as \public_html\BDUDBdev\userpics\b1bf9a988e8748792895d99c4816786f.png instead of to the given directory.

Anyone know what to do?

alexhans1 commented 7 years ago

Okay after trying a few things out, I found that (at least on Windows) the line: path.join(opts.basepath, raw.toString('hex') + path.extname(file.originalname))) tuns slashes in backslashes.

My fix:

String.prototype.replaceAll = function(target, replacement) {
  return this.split(target).join(replacement);
};

function getDestination (req, file, opts, cb) {
  random(16).then(function(raw) {

    cb(null, path.join(opts.basepath, raw.toString('hex') + path.extname(file.originalname)).replaceAll("\\", "/"))
  }, cb)
}
UrITSolutions commented 6 years ago

Hi,

I didn't understand, where did you put the above code.