Not able to upload image on server using Api in meteor

144 views Asked by At

I am using 'nimble:restivus' package of meteor to create a api for uploading the image.

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 Request:

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 Code:

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;
    }
});

Server side Response(API):

Please check attached image for console output on server side-- Console output on server side api

When i submitting the form as POST, not able to get the image on server side. As i received body-params but when i tried to get image as this.bodyParams.file, it returns undefined.

Please guide me how i can image on server side after submitting the form. Thanks.

0

There are 0 answers