1

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.

user3931619
  • 267
  • 4
  • 14
  • More information please - are there any error messages? The link you provide is dead – Mikkel Nov 22 '16 at 08:38
  • yes, link is dummy. Actually when i submit my html form on api URL, on api side i am not able to get the Image, i have checked the url params but nothing was there. So how i can get an image on server side by just submitting the form. – user3931619 Nov 22 '16 at 09:57
  • Is it compulsory to read first file on client side then send on server side? – user3931619 Nov 22 '16 at 10:01
  • in order to help you, I (or anyone else) need more information in the form of code and specific error messages. You can read http://stackoverflow.com/help/how-to-ask for some tips – Mikkel Nov 22 '16 at 12:41
  • @Mikkel: I have edited the question with full info, Please check. Thanks – user3931619 Nov 23 '16 at 06:32

0 Answers0