sketch icon indicating copy to clipboard operation
sketch copied to clipboard

无法加载Windows下网络驱动器中的图片

Open michaellee123 opened this issue 3 months ago • 3 comments

局域网内共享文件夹,不挂载盘符的情况下,在Windows下面出来的uri是:

\\dir\dir\file.jpg

然后再通过uri.path出来,斜线方向又有变化:

//dir/dir/file.jpg

这个uri无法通过 isFileUri 的校验,导致不会按照文件的方式去加载它,同时手动跳过isFileUri后依然无法通过uri.path.orEmpty().toPath()构建出正确的path,但是实际上却是可以用的,我自己增加了一个Fetcher来加载它,实测可用:

import com.github.panpf.sketch.fetch.Fetcher
import com.github.panpf.sketch.fetch.FileUriFetcher
import com.github.panpf.sketch.request.RequestContext
import okio.Path.Companion.toOkioPath
import java.io.File

class SketchWindowsNetworkFetcher : Fetcher.Factory {
    override fun create(requestContext: RequestContext): Fetcher? {
        val uri = requestContext.request.uri
        val path = uri.path?:""
        if (!path.startsWith("\\\\") && !path.startsWith("//")) return null
        return FileUriFetcher(
            path = File(path).toOkioPath(),
            fileSystem = requestContext.sketch.fileSystem
        )
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        return other != null && this::class == other::class
    }

    override fun hashCode(): Int {
        return this::class.hashCode()
    }

    override fun toString(): String = "WindowsNetworkFileUriFetcher"

}

michaellee123 avatar Sep 10 '25 13:09 michaellee123

好的,下个版本会修复这个问题

panpf avatar Sep 10 '25 13:09 panpf

你在构建 ImageRequest 时是怎么创建的 uri?

panpf avatar Sep 11 '25 03:09 panpf

val uri = newFileUri(file) //file是java的File,方法是com.github.panpf.sketch.fetch中的

michaellee123 avatar Oct 28 '25 19:10 michaellee123