最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何使用dropzone.js和hapi.js上传图像

IT培训 admin 7浏览 0评论

如何使用dropzone.js和hapi.js上传图像

在这个tutorial之后,我正在尝试将图像文件上传到我的hapi.js服务器。我遇到了这个错误:

CORS错误:不允许使用某些标头

这是我的客户端设置(这是在localhost:3000上运行的react.js Web客户端)

$('#upload')['dropzone']({
    url: 'http://localhost:8000/api/sector/upload',
    method: 'POST',
    headers:{
        'Cache-Control': null, //required for cors
        'X-Requested-With': null, //required for cors,
        'Access-Control-Allow-Origin': '*'                
    }
})

这是我在服务器端的路由(在localhost:8000上运行):

            method: 'POST',
            path: '/api/sector/upload',
            config:{
                cors: true,
                payload:{
                    output: 'stream',
                    parse: true,
                    allow: 'multipart/form-data',
                    maxBytes: 268435456
                }
            },
            handler: function(request, reply) {
               ....
            }

如何在这种情况下启用cors?谢谢你的建议

回答如下:

回答我自己的问题,我使用了这个hapi.js插件hapi-cors-headers,它解决了我的问题(对于一个面临同样的问题)

如何使用dropzone.js和hapi.js上传图像

在这个tutorial之后,我正在尝试将图像文件上传到我的hapi.js服务器。我遇到了这个错误:

CORS错误:不允许使用某些标头

这是我的客户端设置(这是在localhost:3000上运行的react.js Web客户端)

$('#upload')['dropzone']({
    url: 'http://localhost:8000/api/sector/upload',
    method: 'POST',
    headers:{
        'Cache-Control': null, //required for cors
        'X-Requested-With': null, //required for cors,
        'Access-Control-Allow-Origin': '*'                
    }
})

这是我在服务器端的路由(在localhost:8000上运行):

            method: 'POST',
            path: '/api/sector/upload',
            config:{
                cors: true,
                payload:{
                    output: 'stream',
                    parse: true,
                    allow: 'multipart/form-data',
                    maxBytes: 268435456
                }
            },
            handler: function(request, reply) {
               ....
            }

如何在这种情况下启用cors?谢谢你的建议

回答如下:

回答我自己的问题,我使用了这个hapi.js插件hapi-cors-headers,它解决了我的问题(对于一个面临同样的问题)

发布评论

评论列表 (0)

  1. 暂无评论