Javascript 如何在Wordpress中为上传到AmazonS3的对象创建一个数据库行?

Javascript 如何在Wordpress中为上传到AmazonS3的对象创建一个数据库行?,javascript,php,html,amazon-web-services,amazon-s3,Javascript,Php,Html,Amazon Web Services,Amazon S3,在我的Wordpress网站中,用户可以将视频文件直接上传到Amazon S3存储桶(这样文件就不会通过我的Web服务器)。我应该如何跟踪添加的对象(即:我应该在Wordpress数据库中的何处以及如何添加数据项),提供的信息有限,您可以使用ajax发布图像数据。下面是带有图像占位符数据的简单ajax var imgData = {author: 'the-author-id', img_url: 'the-url', img_type: 'the-img-type'} $.ajax({

在我的Wordpress网站中,用户可以将视频文件直接上传到Amazon S3存储桶(这样文件就不会通过我的Web服务器)。我应该如何跟踪添加的对象(即:我应该在Wordpress数据库中的何处以及如何添加数据项)

,提供的信息有限,您可以使用ajax发布图像数据。下面是带有图像占位符数据的简单ajax

var imgData = {author: 'the-author-id', img_url: 'the-url', img_type: 'the-img-type'}

$.ajax({
    data : JSON.stringify(imgData),
    contentType : 'application/json',
    type : 'POST',
    url: 'your-wordpress-post-url',
    success: function () {
        // do something with the success result from backend
    }
});
在WordPress中,您可以使用
wp\u insert\u attachment()



请提供更多信息。视频是否与帖子、用户或其他人关联?您在哪里可以访问上载的详细信息:javascript或php?@Tristan视频与上载它们的特定用户关联。您可以通过javascript访问上载的详细信息
<?php

// Prepare an array of post data for the attachment.
$attachment = array(
    'post_author' => $_POST['author'], 
    'post_date' => current_time('mysql'),
    'guid' => $_POST['img_url'], 
    'post_mime_type' => $_POST['img_type'],
    'post_title' => preg_replace( '/\.[^.]+$/', '', $_POST['img_url'] ),
    'post_content' => '',
    'post_status' => 'inherit',
    'comment_status' => 'closed',
    'ping_status' => 'closed',
);

// Insert the attachment.
$attach_id = wp_insert_attachment( $attachment );

// if fail $attach_id is 0
echo json_encode(array('attach_id' => $attach_id));
?>