如何从流星的网站上传文件到另一个网站?

时间:2016-08-04 11:53:50

标签: file meteor upload meteor-blaze

我的应用程序是使用meteor开发的。但是,我想将文件从客户端上传到另一个Web应用程序(由java开发)。

我正在尝试实现ajax调用。但是,我得到了错误。

的客户机/ upload.js

Template.bulkUserCreation.events({
    'submit form': function (event, template) {
        event.preventDefault();

        var file = template.find('input[type="file"]').files[0];

        var form = event.currentTarget;

        var userUpload = {};

        userUpload.url = Meteor.urlConfig.ADD_TENANT_BULK_USER;
        userUpload.headers['Content-type'] = 'multipart/form-data';
        userUpload.headers.fileSize = file.size;

        var fd = new FormData();

        fd.append('file',file);

        $.ajax({
            url: userUpload.url,
            type: 'POST',
            data: fd,
            headers: userUpload.headers,
            cache: false,
            dataType: 'json',
            processData: false, // Don't process the files
            contentType: false, // Set content type to false as jQuery will tell the server its a query string request
            success: function(data, textStatus, jqXHR)
            {
                if(typeof data.error === 'undefined')
                {
                    // Success so call function to process the form
                    alert('Success');
                }
                else
                {
                    // Handle errors here
                    console.log('ERRORS: ' + data.error);
                }
            },
            error: function(jqXHR, textStatus, errorThrown)
            {
                // Handle errors here
                console.log('ERRORS: ' + textStatus);
                // STOP LOADING SPINNER
            }
        });
    },
});

响应:

XMLHttpRequest cannot load http://192.168.1.120:8080/*********/_bulk?tenantId=1001. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

请帮帮我。如何完成它。

0 个答案:

没有答案