将数据保存到控制器

时间:2013-03-07 11:42:04

标签: c# javascript asp.net-mvc amazon-s3 plupload

我在尝试将使用Plupload上传的数据转移到Amazon S3并将文件名保存到Controller时遇到问题。

表格看起来像这样......

@using (Html.BeginForm("SavePhotos", "QuoteWizard", FormMethod.Post, new { enctype =   "multipart/form-data"}))
{

<div id="uploader">
    <p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
</div>

<input type="hidden" name="key" value="@Model.FileId-${filename}">
<input type="hidden" name="AWSAccessKeyId" value="@Model.PublicKey"> 
<input type="hidden" name="acl" value="@Model.Acl"> 
<input type="hidden" name="success_action_redirect" value="@Model.RedirectUrl">
<input type="hidden" name="policy" value="@Model.Policy">
<input type="hidden" name="signature" value="@Model.Signature">
<input type="file" name="file" />

}

这样的剧本......

$(document).ready(function() {

        $("#uploader").plupload({
            //amazon settings.
            runtimes: 'flash,silverlight',
            url: 'https://[mybucket].s3-eu-west-1.amazonaws.com',
            max_file_size: '10mb',
            multipart: true,
            multipart_params: {
                'key': '${filename}', // use filename as a key
                'Filename': '${filename}', // adding this to keep consistency across the runtimes
                'acl': $('#Acl').val(),
                'Content-Type': 'binary/octet-stream',
                'success_action_status': '201',
                'AWSAccessKeyId': $('#AWSAccessKeyId').val(),
                'policy': $('#Policy').val(),
                'signature': $('#Signature').val()
            },
            preinit: attachCallbacks,
            // optional, but better be specified directly
            //file_data_name: 'file',
            // re-use widget (not related to S3, but to Plupload UI Widget)
            //multiple_queues: true,

            // Resize images on clientside if we can
            //resize: { width: 320, height: 240, quality: 90 },

            // Specify what files to browse for
            filters: [
                // { title: "Video files", extensions: "mp4,m4v,wmv,avi,mov,mpg,mpeg,mkv" }
                { title: "Image files", extensions: "jpg,gif,png" }
            ],

            // Flash settings
            flash_swf_url: '/RAPPMBCVSite/Scripts/plupload/plupload.flash.swf',

            // Silverlight settings
            silverlight_xap_url: '/RAPPMBCVSite/Scripts/plupload/plupload.silverlight.xap'
        });
    });

    function attachCallbacks(Uploader) {
        Uploader.bind('FileUploaded', function(Up, File, Response) {
            if ((Uploader.total.uploaded + 1) == Uploader.files.length) {
                $('form')[0].submit();
                //window.location = 'http://localhost/RAPPMBCVSite/QuoteWizard/LabelPhoto';
            }
        });

    }

这样的控制器(目前这是最小的)

[HttpPost]
    public virtual ActionResult SavePhotos(HttpPostedFileBase file)
    {
        HttpPostedFileBase FileData = Request.Files[0];
        return RedirectToAction(MVC.QuoteWizard.LabelPhoto());
    }

我在Stack Exchange上找到了几个答案,但其中没有一个是有效的。

目前传递给控制器​​的数据为空。

提前感谢您的帮助。

0 个答案:

没有答案