diff --git a/interfaces/kits/js/src/mod_fs/properties/open.cpp b/interfaces/kits/js/src/mod_fs/properties/open.cpp index 5102cbdf7a2c65bd157531fc70e55bf101a7946f..10dc568e6dfd368825a9ef91d2ecc0ffaa5171ce 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open.cpp @@ -57,6 +57,25 @@ static tuple GetJsFlags(napi_env env, const NFuncArg &funcAr return { true, mode }; } +static string DealWithUriWithName(string str) +{ + static uint32_t MEET_COUNT = 6; + uint32_t count = 0; + uint32_t index; + for (index = 0; index < str.length(); index++) { + if (str[index] == '/') { + count++; + } + if (count == MEET_COUNT) { + break; + } + } + if (count == MEET_COUNT) { + str = str.substr(0, index); + } + return str; +} + static NVal InstantiateFile(napi_env env, int fd, string pathOrUri, bool isUri) { napi_value objFile = NClass::InstantiateClass(env, FileNExporter::className_, {}); @@ -107,6 +126,9 @@ static int OpenFileByDatashare(string path, unsigned int flags) HILOGE("Failed to connect to datashare"); return -E_PERMISSION; } + HILOGI("Before Media Path is %{public}s", path.c_str()); + path = DealWithUriWithName(path); + HILOGI("After Media Path is %{public}s", path.c_str()); Uri uri(path); fd = dataShareHelper->OpenFile(uri, CommonFunc::GetModeFromFlags(flags)); return fd;