2014-10-10 128 views
0

我创建了一个使用LocomotiveCMS的网站,我创建了两种称为照片和图库的内容类型,这些内容类型有一个关系,以便我可以在我的网站上创建图像库。如何通过机车CMS创建新的内容条目CMS RESTful API

我目前正在寻找使用RESTful API来为照片创建多个内容条目,因为它穿过一个文件。

我可以连接到API,没有问题,修改网站等

我会假设,一个新的内容条目卷曲命令将采取以下形式:

curl -X POST -d 'photo[image_id]=blah&photo[gallery]=1234&photo[file]=<filepath>photo[published]=true' 'http://<your site>/locomotive/api/current_site.json?auth_token=xxxx' 

不过我我不确定如何通过这个命令传递一个文件,我现在已经替换了这个文件,你会如何编写这个部分?

我字段设置为图片如下:

fields: 

- image_id: 
label: Image ID 
type: string 
required: true 
localized: false 

- file: # Name of the field 
label: File 
type: file 
required: true 
localized: false 

- gallery: # Name of the field 
label: Gallery 
type: belongs_to 
required: true 
localized: false 
# Slug of the target content type (eg post if this content type is a comment) 
class_name: gallery 

回答

0

我最终作出一个Ruby脚本解析文件,并将其上传通过后的数据发送到

/locomotive/api/content_types/photos/entries.json?auth_token=XXXX 
0

下面的代码可能有助于此任务:

data = { 
    content_entry: { 
     title: 'Title', 
     image: File.new('media/images/screen.png'), 
    } 
} 

HTTMultiParty.post(
    "http://localhost:8080/locomotive/content_types/blogs/entries.json?auth_token=#{@token}", 
    query: data, 
    headers: { 'Content-Type' => 'application/json' } 
) 

我使用HTTMultiParty,因为我们实际上需要做一个多部分职位。如何与卷曲做到这一点有用的信息: https://github.com/locomotivecms/documentation/pull/175

获得令牌,你需要这样的事:

HTTParty.post(
    'http://localhost:8080/locomotive/api/tokens.json', 
    body: { api_key: 'YOUR_API_KEY_HERE' } 
) 

我希望帮助。

相关问题