lundi 18 janvier 2016

Upload photo using Ember addon ember-plupload

I have used ember-plupload for uploading the images.Now I have written a component for this.I am able to open and select the images from my machine.But I am lost what to do next.I have to send the post request to my server endpoint with body params { photo_file: image file }.My code is following.

component.hbs

{{#pl-uploader extensions="jpg jpeg png gif" for="upload-image" onfileadd="uploadImage" as |queue features|}}
  <div class="dropzone" id={{dropzone.id}}>
    <a id="upload-image">Add an Image.</a>
  </div>
{{/pl-uploader}}

component.js

actions:{
        uploadImage:function(file){
        console.log(file)
        let filename = file.get('name');
        file.read().then(function (url) {
         console.log(filename)
         console.log(url)
        }
      }

I am able to get the file name and encode base64 value.But not sure how to send the request to server endpoint.

http://ift.tt/1QhQpjs and it require body with parameter photo_file and choosed file.

I am able to make the correct request from postman app.In the body of the request ,I am selecting the file option and it directly gives me the option to choose a file from there itself.The request is made successfully and photo gets added to endpoint when I select an image and send request

How should I do it in my app?




Aucun commentaire:

Enregistrer un commentaire