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

新建文件夹报错 #305

Open
rxszcn opened this issue Nov 4, 2024 · 7 comments
Open

新建文件夹报错 #305

rxszcn opened this issue Nov 4, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@rxszcn
Copy link

rxszcn commented Nov 4, 2024

新建文件夹报错。

jmal-cloud-view\src\components\ShowFile\ShowFile.vue

    getQueryPath() {
      // 去掉this.$route.query.basePath最后的/
      let basePath = this.$route.query.basePath
        ? this.$route.query.basePath
        : '/'
      if (basePath) {
        if (basePath.lastIndexOf('/') === basePath.length - 1) {
          basePath = basePath.substring(0, basePath.length - 1)
        }
      }
      return encodeURI(basePath + this.$route.query.path)
    }

返回undefined。

去掉换行

    getQueryPath() {
      // 去掉this.$route.query.basePath最后的/
      let basePath = this.$route.query.basePath ? this.$route.query.basePath : '/'
      if (basePath) {
        if (basePath.lastIndexOf('/') === basePath.length - 1) {
          basePath = basePath.substring(0, basePath.length - 1)
        }
      }
      return encodeURI(basePath + this.$route.query.path)
    }

返回空字符串。

注释掉以下

    getQueryPath() {
      // 去掉this.$route.query.basePath最后的/
      let basePath = this.$route.query.basePath ? this.$route.query.basePath : '/'
      // if (basePath) {
      //   if (basePath.lastIndexOf('/') === basePath.length - 1) {
      //     basePath = basePath.substring(0, basePath.length - 1)
      //   }
      // }
      return encodeURI(basePath + this.$route.query.path)
    }

可以正常上传。

@jamebal
Copy link
Owner

jamebal commented Nov 4, 2024

感谢反馈, 请问是什么版本, 什么情况下新建文件夹报错

@rxszcn
Copy link
Author

rxszcn commented Nov 4, 2024

感谢反馈, 请问是什么版本, 什么情况下新建文件夹报错

刚拉取的版本。初始化项目后通过地址 http://localhost:9528/ 访问,直接新建文件夹。
我改成了

getQueryPath() {
      // 去掉this.$route.query.basePath最后的/
      let basePath
      if (this.$route.query.basePath) {
        basePath = this.$route.query.basePath
        if (basePath) {
          if (basePath.lastIndexOf('/') === basePath.length - 1) {
            basePath = basePath.substring(0, basePath.length - 1)
          }
        }
      } else {
        basePath = '/'
      }
      return encodeURI(basePath + this.$route.query.path)
    }

但 this.$route.query.path没有值的的时候返回还会拼成"/undefined"

后台打印

2024-11-04 16:06:01.336 |INFO |Thread-3 |FileListener.java:108 |com.jmal.clouddisk.listener.FileListener |用户:null,修改目录:D:\netdisk\storage\admin
2024-11-04 16:06:01.340 |INFO |Thread-3 |FileListener.java:95 |com.jmal.clouddisk.listener.FileListener |用户:admin,新建目录:D:\netdisk\storage\admin\undefined
2024-11-04 16:06:01.342 |INFO |Thread-3 |FileListener.java:95 |com.jmal.clouddisk.listener.FileListener |用户:admin,新建目录:D:\netdisk\storage\admin\undefined\新建文件夹

@jamebal
Copy link
Owner

jamebal commented Nov 4, 2024

根目录时, getQueryPath()方法返回undefined

@jamebal
Copy link
Owner

jamebal commented Nov 4, 2024

后端处理了undefined

public String getCurrentDirectory() {
        if (currentDirectory == null || "undefined".equals(currentDirectory)) {
            return File.separator;
        }
        if (File.separator.equals("\\")) {
            // Windows 系统
            currentDirectory = currentDirectory.replace("/", "\\");
        }
        return URLUtil.decode(currentDirectory);
    }

@rxszcn
Copy link
Author

rxszcn commented Nov 4, 2024

后端处理了undefined

public String getCurrentDirectory() {
        if (currentDirectory == null || "undefined".equals(currentDirectory)) {
            return File.separator;
        }
        if (File.separator.equals("\\")) {
            // Windows 系统
            currentDirectory = currentDirectory.replace("/", "\\");
        }
        return URLUtil.decode(currentDirectory);
    }

后端有处理我把前端的修改撤回了,最早原因是新建文件夹和上传文件都报错误
在类CommonFileService

    public String getUserDirectoryFilePath(UploadApiParamDTO upload) {
        String currentDirectory = upload.getCurrentDirectory();
        if (CharSequenceUtil.isBlank(currentDirectory)) {
            currentDirectory = fileProperties.getSeparator();
        }
        Path path;
        if (Boolean.TRUE.equals(upload.getIsFolder())) {
            System.out.println("currentDirectory: " + currentDirectory);
            System.out.println("FolderPath: " + upload.getFolderPath());
            System.out.println("Filename: " + upload.getFilename());
            path = Paths.get(currentDirectory, upload.getFolderPath(), upload.getFilename());
        } else {
            path = Paths.get(currentDirectory, upload.getRelativePath());
        }
        return path.toString();
    }

currentDirectory:
FolderPath:
Filename: 新建文件夹
2024-11-04 16:44:31.874 |ERROR |http-nio-8088-exec-2 |CommonExceptionHandler.java:36 |com.jmal.clouddisk.exception.CommonExceptionHandler |UNC path is missing sharename: \新建文件夹
java.nio.file.InvalidPathException: UNC path is missing sharename: \新建文件夹
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:118)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:232)
at java.base/java.nio.file.Path.of(Path.java:147)
at java.base/java.nio.file.Paths.get(Paths.java:69)
at com.jmal.clouddisk.service.impl.CommonFileService.getUserDirectoryFilePath(CommonFileService.java:179)
at com.jmal.clouddisk.service.impl.CommonFileService.createFolder(CommonFileService.java:288)
at com.jmal.clouddisk.service.impl.FileServiceImpl.uploadFolder(FileServiceImpl.java:1758)
at com.jmal.clouddisk.controller.rest.FileController.uploadFolder(FileController.java:133)
at jdk.internal.reflect.GeneratedMethodAccessor91.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:351)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:765)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
at com.jmal.clouddisk.acpect.PermissionAspect.before(PermissionAspect.java:71)
at jdk.internal.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:637)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:627)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:71)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:173)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:765)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
at com.jmal.clouddisk.acpect.LogOperatingAspect.interceptor(LogOperatingAspect.java:53)
at jdk.internal.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:637)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:627)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:71)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:173)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:765)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:765)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:717)
at com.jmal.clouddisk.controller.rest.FileController$$SpringCGLIB$$0.uploadFolder()
at jdk.internal.reflect.GeneratedMethodAccessor91.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:255)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:188)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:925)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:830)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
at com.jmal.clouddisk.config.WebFilter.doFilter(WebFilter.java:34)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:735)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:842)

经测试参数确实会报错,我是Windows开发环境。

    public static void main(String[] args) {
        System.out.println(Paths.get("\\", "", "新建文件夹"));
    }

GPT回复
Paths.get("\", "", "新建文件夹") 报错的原因是,Java Paths.get() 方法在处理 Windows 路径时,对于使用“反斜杠 \”作为根路径的路径字符串,会将其识别为 UNC(Universal Naming Convention)路径。UNC 路径要求包含共享名(例如 \server\share\path)。如果仅仅写为 \新建文件夹,缺少共享名,则会抛出 InvalidPathException 错误。

@jamebal
Copy link
Owner

jamebal commented Nov 4, 2024

Windows环境, 确实有些问题

@rxszcn
Copy link
Author

rxszcn commented Nov 4, 2024

    /***
     * 用户磁盘目录
     * @param upload UploadApiParamDTO
     * @return 目录路径
     */
    public String getUserDirectoryFilePath(UploadApiParamDTO upload) {
        String currentDirectory = upload.getCurrentDirectory();
        if (CharSequenceUtil.isBlank(currentDirectory)) {
            currentDirectory = fileProperties.getSeparator();
        }
        Path path;
        if (Boolean.TRUE.equals(upload.getIsFolder())) {
            path = Paths.get(currentDirectory).resolve(upload.getFolderPath()).resolve(upload.getFilename());
            //path = Paths.get(currentDirectory, upload.getFolderPath(), upload.getFilename());
        } else {
            path = Paths.get(currentDirectory).resolve(upload.getRelativePath());
            //path = Paths.get(currentDirectory, upload.getRelativePath());
        }
        return path.toString();
    }

我改成这样,测试正常了。另外Windows开发环境删除目录后不会自动刷新,需要手动刷新该目录才会从页面消失。Linux下测试没问题。

@jamebal jamebal added the bug Something isn't working label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants