AmazonS3直接上传POST表单中的额外输入字段

时间:2013-07-10 20:59:46

标签: asp.net-mvc-4 amazon-web-services amazon-s3

我在POST表单中添加了一个额外的“title”字段,并在我的模型中创建了一个“title”属性。视频上传后,服务器将被定向到另一个控制器。这可以通过在策略文件中设置重定向字段来完成。现在我如何访问重定向控制器中的标题字段?

POST表单:

<form action="@Model.FileUploadModel.FormAction" method="@Model.FileUploadModel.FormMethod" enctype="@Model.FileUploadModel.FormEnclosureType" >

                     <input type="hidden" name="key" value="@Model.FileUploadModel.FileId" /> 
                     <input type="hidden" name="AWSAccessKeyId" value="@Model.FileUploadModel.AWSAccessKey" /> 
                     <input type="hidden" name="acl" value="@Model.FileUploadModel.Acl" /> 
                     <input type="hidden" name="policy" value="@Model.FileUploadModel.Base64EncodedPolicy" /> 
                     <input type="hidden" name="signature" value="@Model.FileUploadModel.Signature" /> 
                     <input type="hidden" name="redirect" value="@Model.FileUploadModel.RedirectUrl" /> 
                     <div class="row">  
                            **<label for="Title" style="padding-right: 5px;">Title (optional) </label>
                            <input type="text" name="Title"  style="width: 200px;" />**
                     </div>
                     <div class="row_clear"></div>
                     <div class="row">
                             <input type="file" name="file" size="100" id="file"/> 
                     </div>
               </form>

和我的FileUploadModel

    public FileUploadModel(string publicKey, string privateKey, string bucketName, string redirectUrl)
    {
        myPrivateKey = privateKey;

        FormAction = string.Format("https://{0}.s3.amazonaws.com/", bucketName);
        FormMethod = "post";
        FormEnclosureType = "multipart/form-data";
        Bucket = bucketName;
        FileId = "u5/i/" + Guid.NewGuid().ToString(); 
        AWSAccessKey = publicKey;
        Acl = "private"; 

      RedirectUrl = redirectUrl;
    }
    public string FormAction { get; private set; }
    public string FormMethod { get; private set; }
    public string FormEnclosureType { get; private set; } 
    public string Bucket { get; private set; }
    public string Acl { get; private set; }
    public string Policy { get; private set; }
    public string FileId { get; private set; }
    public string AWSAccessKey { get; private set; }
    public string RedirectUrl { get; private set; }
    [Display(Name = "Title (optional)")]
    public string Title { get; set; }
    [Display(Name = "File")]
    public HttpPostedFileBase File { get; set; }
    public int? Page { get; set; }
    public string SearchString { get; set; }

}

}

以下是我提及的用于创建政策表单的链接。

Link

1 个答案:

答案 0 :(得分:0)

我通过URL发送title属性解决了这个问题。

在我的RouteConfig文件中,我添加了一条新路线:

 routes.MapRoute(
                name: "Transcode",
                url: "{controller}/{action}/{title}/{id}",
                defaults: new
                {
                    controller = "Videos",
                    action = "Transcode",
                    id = UrlParameter.Optional
                }
            );

然后在Transcode动作中我添加了一个title参数。最后,我传递给重定向网址属性的值是:“http://dev.area.local/Videos/Transcode/title