Alexander Borovoi Alexander Borovoi - 28 days ago 11
reST (reStructuredText) Question

Angular2 image upload with Rest

I have Rest API

I use ng2-file-upload like this

My backend recieves following data

{"file"=>"#<ActionDispatch::Http....bla bla.."}


When i am using rails front end - its ok. I need fix angular2. My backend is waiting data like this:

"photo"=>{"title"=>"qwerty", "image"=> "#<ActionDispatch::Http...blabla..."}


I change

this.alias = uploader.options.itemAlias || 'file';


to

this.alias = uploader.options.itemAlias || 'image';


But I don't no how append
'photo'=>
before form.
I deployed simple backend on heroku https://backend-file-upload.herokuapp.com/photos

Github apibackend - this
Angular2 deployed - this
. If this problem be fix, I will be start to create my project. Please help.)))

Answer

I suggest you take a look at ng2-file-upload.

Just tweak uploader settings and you should be good to go

uploader:FileUploader = new FileUploader({url: URL});

Documentation is a bit incomplete, so take a look at the demo.