ruby on rails - How to upload images for products using Spree Commerce REST API -


i have migrate old eshop new, made on spree. has api it.

but stuck uploading images remote server. here doing on making new product:

require 'nokogiri' require 'open-uri' require 'curb' require 'uri'  http = curl.post("http://domain/api/products?product[name]=test\   &product[price]=123\   &product[shipping_category_id]=1\   &product[taxon_ids]=52\   &product[sku]=020323232\   &product[image]=http://www.computercloset.org/altair_8800_and_santa.jpg") |http|     http.headers['x-spree-token'] = 'd60ff5896cef2920d83f18c11b95ee1dff8d9c82d1480cbc' end 

the product saving parameters, except image.

i think have wrong syntax, unable find example or uploading images on http://guides.spreecommerce.com/api/

you won't able create image way.

your best bet create images directly using undocumented api call:

https://github.com/spree/spree/blob/v2.2.0/api/app/controllers/spree/api/images_controller.rb

as of 2.2.0, can specify following parameters: :alt, :attachment, :position, :viewable_type, :viewable_id

i expect may find insufficient doing you're looking for. in particular, you'll need upload files separately process. create image record showing stored (which goes through paperclip). specifying full url have listed not work. need filename file stored in place paperclip stores images.

this isn't ideal experience, why api call undocumented. if you're able modify make work bit better should send pull request spree team. i'm sure they'd happy receive it.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -