首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Antd upload的Dragger组件跨域上传

Antd upload的Dragger组件跨域上传
EN

Stack Overflow用户
提问于 2018-11-19 22:21:49
回答 1查看 1.1K关注 0票数 0

我使用create-react-app来做我的前端工作,并在antd的上传中使用Dragger组件。我的后端是springboot。我的前端使用fetch向后端发送请求数据,这会导致跨域问题。所以我在create-react-app的package.json文件中添加了" proxy“:"http://localhost:8080”来代理我的后端,解决了跨域的麻烦,但是当我使用antd官网时,上传的拖拽组件总是在上传的时候报告错误。

这是我使用Antd的Dragger的代码。

代码语言:javascript
复制
import React, { Component } from 'react';
import { Upload, Icon, message } from 'antd';
import './UpVideo.css';

const Dragger = Upload.Dragger;

导出默认类UpVideo扩展了组件{

代码语言:javascript
复制
render(){

    const props = {
        name: 'file',
        multiple: false,
        headers:{
            'Access-Control-Allow-Origin':'*',
            'Access-Control-Allow-Methods':'POST',

        },
        action: 'http://localhost:8080/vidoe/up',
        onChange(info) {
        //   const status = info.file.status;
          console.log(info);
        //   if (status !== 'uploading') {
        //     console.log(info.file, info.fileList);
        //   }
        //   if (status === 'done') {
        //     message.success(`${info.file.name} file uploaded successfully.`);
        //   } else if (status === 'error') {
        //     message.error(`${info.file.name} file upload failed.`);
        //   }
        },
      };

    return(
        <div>

            <Dragger {...props}>
                <p className="ant-upload-drag-icon">
                <Icon type="inbox" />
                </p>
                <p className="ant-upload-text">点击或者拖动视频文件到这里</p>
            </Dragger>,
        </div>
    )
}

}

这是我给出的错误图片。

对不起,我刚学会使用StackOverflow。如果我的描述不清楚,请让我知道,这个问题已经困扰我很长时间了,谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-05-07 06:53:51

这个错误是google chrome的一个安全措施。当您使用两个不同的服务器作为前端和后端时,它会出现。安装此库以修复此问题:

npm安装cors https://www.npmjs.com/package/cors

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53376630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档