无法使用流星图中的Api在服务器上上传图像

时间:2016-11-22 08:00:28

标签: node.js meteor https image-uploading meteor-restivus

我正在使用&nbspble:restivus'流星包用于创建用于上传图像的API。

HTML:

<form id="upload" onSubmit="upload()">
 <input type="file" id="avatar" name="avatar" />
 <input type="text" id="fname" name="fname" />
 <button type="submit">Submit</button>
</form>

Ajax请求:

var file_data = $("#avatar").prop("files")[0];
var form_data = new FormData();
form_data.append("file", file_data);
form_data.append("userId", '8NrAn4sR3bKmXi84u');
form_data.append("fileName", file_data.name);
$.ajax({
    url: "http://localhost:3000/api/v1/uploadImages/",
    cache: false,
    contentType: 'application/x-www-form-urlencoded; charset=utf-8',
    processData: false,
    data: form_data,
    type: 'POST'
});

Api代码:

var Api = new Restivus({
    version: 'v1',
    useDefaultAuth: true
});
Api.addRoute('uploadImages', { authRequired: false }, {
    post: function(){
        console.log("=====> UPLOAD IMAGES API <======");
        console.log("this.bodyParams -> ",this.bodyParams)
        return true;
    }
});

服务器端响应(API):

请检查服务器端控制台输出的附加图像 - Console output on server side api

当我以POST格式提交表单时,无法在服务器端获取图像。当我收到body-params但是当我试图将图像作为this.bodyParams.file时,它返回undefined。

请在提交表单后指导我如何在服务器端进行映像。 感谢。

0 个答案:

没有答案