From bfab760a279291a12b756f5b8624b2196d9ab1bb Mon Sep 17 00:00:00 2001 From: Pierluigi Minardi Date: Fri, 9 Jul 2021 22:50:20 +0200 Subject: Fix on the path format + function to recognize the OS --- src/components/ui/ImageUpload.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/components/ui') diff --git a/src/components/ui/ImageUpload.js b/src/components/ui/ImageUpload.js index 6a8c7645f..4151d871b 100644 --- a/src/components/ui/ImageUpload.js +++ b/src/components/ui/ImageUpload.js @@ -25,12 +25,24 @@ export default @observer class ImageUpload extends Component { dropzoneRef = null; + imgPath = null; + onDrop(acceptedFiles) { - const { field } = this.props; + const { field } = this.props; acceptedFiles.forEach((file) => { + console.log(this.getOS()); + + if(this.getOS() === "Windows"){ + this.imgPath = file.path.replace(/\\/g,"/"); + }else{ + this.imgPath = file.path; + } + + console.log(this.imgPath); + this.setState({ - path: file.path, + path: this.imgPath, }); this.props.field.onDrop(file); }); @@ -38,6 +50,23 @@ export default @observer class ImageUpload extends Component { field.set(''); } + getOS() { + var platform = window.navigator.platform, + macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], + windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'], + os = null; + + if (macosPlatforms.indexOf(platform) !== -1) { + os = 'Mac OS'; + } else if (windowsPlatforms.indexOf(platform) !== -1) { + os = 'Windows'; + } else if (!os && /Linux/.test(platform)) { + os = 'Linux'; + } + + return os; + } + render() { const { field, className, multiple, textDelete, textUpload, -- cgit v1.2.3-70-g09d2