z***@126.com
z***@126.com
  • 发布:2024-05-31 10:35
  • 更新:2024-05-31 15:50
  • 阅读:571

uni-file-picker上传组件报错,

分类:uni-app

自动上传时,提示 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

空间是支付宝云 , uni-file-picker上传组件报错怎么办?

我的支付宝云
内置云存储上传域名:
https://u.object.cloudrun.cloudbaseapp.cn
内置云存储下载域名:
https://env-00jxgsvtwur4.normal.cloudstatic.cn

和请求的不一样。

2024-05-31 10:35 负责人:无 分享
已邀请:
套马杆的套子

套马杆的套子 - 找AI、用AI、信AI

这报错跨域了
跨域配置配了么

或者给上传处的代码贴出来,我试试

z***@126.com

z***@126.com (作者) - 你好

<uni-file-picker
v-model="imageValue"
fileMediatype="all"
mode="grid"

            @select="select"   
            @progress="progress"   
            @success="success"   
            @fail="fail"   
            ref="files"  
            sizeType="['compressed']"  
        />  

云空间 跨域默认有配置

套马杆的套子

套马杆的套子 - 找AI、用AI、信AI

我刚用阿里云试了下面代码是没问题的,支付宝云等会我试试,我这支付宝云现在有点问题

<template>  
    <view>  
        <uni-file-picker v-model="imageValue" fileMediatype="image" mode="grid" @select="select" @progress="progress"  
            @success="succes1s" @fail="fail1" />  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                imageValue: []  
            }  
        },  
        methods: {  
            // 获取上传状态  
            select(e) {  
                console.log('选择文件:', e)  
            },  
            // 获取上传进度  
            progress(e) {  
                console.log('上传进度:', e)  
            },  

            // 上传成功  
            succes1s(e) {  
                console.log('上传成功')  
            },  

            // 上传失败  
            fail1(e) {  
                console.log('上传失败:', e)  
            }  
        }  
    }  
</script>  

<style>  

</style>  
  • z***@126.com (作者)

    你解决了吗?

    2024-05-31 12:39

  • 套马杆的套子

    回复 3***@qq.com: 你的前端网页托管开通了没?

    2024-05-31 14:52

  • z***@126.com (作者)

    回复 套马杆的套子: 没有,本地测试开发,用 uniCloud.uploadFile 也是提示跨域错误

    2024-05-31 15:41

z***@126.com

z***@126.com (作者) - 你好

本地开发,上传图片功能,还要配置域名吗?
本地开发,上传图片,还要配置域名吗?

套马杆的套子

套马杆的套子 - 找AI、用AI、信AI

重新搞了个支付宝云服务空间,用下面代码测的,没问题
前端网页托管是打开的,跨域配置也配了,但是,是自动配的

<template>  
    <view>  
        <uni-file-picker v-model="imageValue" fileMediatype="image" mode="grid" @select="select" @progress="progress"  
            @success="succes1s" @fail="fail1" />  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                imageValue: []  
            }  
        },  
        methods: {  
            // 获取上传状态  
            select(e) {  
                console.log('选择文件:', e)  
            },  
            // 获取上传进度  
            progress(e) {  
                console.log('上传进度:', e)  
            },  

            // 上传成功  
            succes1s(e) {  
                console.log('上传成功')  
            },  

            // 上传失败  
            fail1(e) {  
                console.log('上传失败:', e)  
            }  
        }  
    }  
</script>  

<style>  

</style>  

该问题目前已经被锁定, 无法添加新回复