我有一个json编码数据,我需要上传到aws dynamoDB
我按照这些link1& link2个链接。但是我的数据没有上传到数据库
我是发电机的新手。任何人都可以帮助我..
让我分享我的json ..
Json.php
has_attached_file :photo,
:styles => {
:thumb=> "",
:small => ""},
:path => "uploads/:class/:attachment/:id_partition/:style/:basename.:extension",
:url => "uploads/:class/:attachment/:id/:style/:basename.:extension"
答案 0 :(得分:0)
我已经找到了解决方案 我认为这可能会对将来有所帮助 我遵循 Marshaler 方法。
require('aws/aws-autoloader.php');
use Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Marshaler;
// --------------------------------------------------------------------
$feed_url = 'http://localhost/json/j_xml.xml';
$xml_data = simplexml_load_file($feed_url);
// --------------------------------------------------------------------
$i=0;
$results = array('return' => true,'message' => 'success','details' => array(),'response'=>array());
$AWS_ACCESS_KEY_ID = '******************';
$AWS_SECRET_ACCESS_KEY = '*******************';
$AWS_REGION = '<region-code>';
$client = DynamoDbClient::factory(array(
'version' => '2012-08-10',
'credentials' => array(
'key' => $AWS_ACCESS_KEY_ID,
'secret' => $AWS_SECRET_ACCESS_KEY,
),
'region' => $AWS_REGION
));
$marshaler = new Marshaler();
foreach($xml_data->channel->item as $ritem) {
$e_wp = $ritem->children("wp", true);
$e_author = $ritem->children("dc", true);
$e_content = $ritem->children("content", true);
// --------------------------------------
if((string)$e_wp->status =='publish') {
$post_id = (string)$ritem->guid;
$post_id = explode('=', $post_id);
$content['ArticleID'] = $post_id[1];
$content['article_title'] = (string)$ritem->title;
$content['article_cat_slug'] = 'News'.$post_id[1];
$content['article_mob_title'] = (string)$ritem->title;
$content['article_category'] = (string)$ritem->category;
$content['article_pub_date'] = (string)$e_wp->post_date;
$content['article_description'] = (string)$ritem->description;
$content['article_content'] = (string)$e_content->encoded;
$content['article_author'] = (string)$e_author->creator;
/* DynamoDB doesnot accept empty string
$content['article_seo_desc'] = '';
$content['article_seo_tags'] = '';
$content['article_fb_title'] = '';
$content['article_fb_desc'] = '';
$content['article_twitter'] = '';
*/
$content['article_create_date'] = (string)$e_wp->post_date_gmt;
$content['article_status'] = (string)$e_wp->status;
$content = array_filter($content);
$json = json_encode($content,JSON_PRETTY_PRINT);
$response = $client->putItem([
'TableName' => 'Article',
'Item' => $marshaler->marshalJson($json)
]);
}
array_push($results['details'],$content);
array_push($results['response'],$response);
}