uni-app中uni-file-picker不返回fileID和url

uni-app中uni-file-picker不返回fileID和url

如图所示,小程序正式版uni-file-picker不返回fileID和url
同时,小程序体验版无此问题,请问什么原因

https://www.itying.com/uniimg.php?url=https://img-cdn-tc.dcloud.net.cn/uploads/questions/20230819/c136dc3a2ce16bac0ec375252988ddd6.jpeg

5 回复

uniCloud.chooseAndUploadFile返回chooseAndUploadFile:ok,但是tempFiles的errMsg是uploadFile:fail url not in domain list
{
“errMsg”: “chooseAndUploadFile:ok”,
“tempFilePaths”: [
“wxfile://tmp_1affe4380259913b7197a106d85f101a4ebddee67acd5f8e.jpg”
],
“tempFiles”: [
{
“path”: “wxfile://tmp_1affe4380259913b7197a106d85f101a4ebddee67acd5f8e.jpg”,
“size”: 53886,
“name”: “tmp_1affe4380259913b7197a106d85f101a4ebddee67acd5f8e.jpg”,
“fileType”: “image”,
“cloudPath”: “1692445712907_0.jpg”,
“uuid”: 1692445712910,
“errMsg”: “uploadFile:fail url not in domain list”
}
]
}

更多关于uni-app中uni-file-picker不返回fileID和url的实战教程也可以访问 https://www.itying.com/category-93-b0.html


腾讯云还是阿里云,小程序端上传安全域名怎么配置的

请问 解决了么?

你好,我也遇到这个问题了,请问您解决了么

在uni-app中,uni-file-picker 组件用于选择文件,通常它会返回文件的相关信息,包括 fileIDurl。如果 uni-file-picker 不返回 fileIDurl,这可能是由于几个原因导致的,比如文件选择未成功、权限问题、或者是组件使用方式不正确。以下是一个使用 uni-file-picker 的基本示例,并展示如何获取 fileIDurl

首先,确保你的项目中已经正确安装了 uni-ui 库,因为 uni-file-pickeruni-ui 的一部分。

npm install @dcloudio/uni-ui

然后在页面中引入并使用 uni-file-picker

<template>
  <view>
    <uni-file-picker
      @change="handleFileChange"
      :count="9"
      :mode="['image']"
      :limit="9"
      :auto-upload="false"
    ></uni-file-picker>
  </view>
</template>

<script>
import { ref } from 'vue';
import UniFilePicker from '@dcloudio/uni-ui/lib/uni-file-picker/uni-file-picker.vue';

export default {
  components: {
    UniFilePicker
  },
  setup() {
    const handleFileChange = (e) => {
      const files = e.detail.files;
      files.forEach(file => {
        console.log('File ID:', file.fileID);
        console.log('URL:', file.url);
        
        // 如果需要上传文件,可以使用uni.uploadFile接口
        // 示例代码略,具体可参考uni-app官方文档
      });
    };

    return {
      handleFileChange
    };
  }
};
</script>

<style>
/* 根据需要添加样式 */
</style>

在这个示例中,我们使用了 Vue 3 的 Composition API。uni-file-picker@change 事件会在文件选择变化时触发,返回的文件信息中包含 fileIDurl

注意事项

  1. 权限问题:确保应用已经请求并获得了必要的文件访问权限。
  2. 组件属性:检查 uni-file-picker 的属性设置,比如 auto-upload,如果设置为 true,文件会自动上传,你可能需要在 upload-complete 事件中获取 fileIDurl
  3. 文件类型:确保选择的文件类型与 mode 属性匹配。
  4. 版本兼容性:检查 uni-appuni-ui 的版本是否兼容。

如果以上都确认无误,但问题仍然存在,建议检查控制台是否有错误信息,或者查阅最新的 uni-appuni-ui 文档以获取更多信息。

回到顶部