Question

I am able to upload a file directly from client browser to amazon s3 using policy and signature using the following code.

<form method="post" enctype="multipart/form-data" id="fileupload">
<input type="hidden" name="key" value="@Model.FileID" />
   <input type="hidden" name="AWSAccessKeyId" value="@Model.AWSAccessKey" />
    <input type="hidden" name="acl" value="@Model.Acl" />
    <input type="hidden" name="policy" value="@Model.Base64EncodedPolicy" />
    <input type="hidden" name="signature" value="@Model.Signature" />
    <input type="hidden" name="success_action_status" value="201" />
<table>
    <tr>
        <td>
            <b> Upload new video : </b>
        </td>
        <td>
            <input type="file" name="file" />
        </td>
    </tr>
</table>
<br />
<input type="button" value="Upload Video" onclick="uploadFile()" />
<div id="progressNumber"></div>
</form>

I need to implement ajax call for the file upload to Amazon S3. I have configured CORS in Configuration of Amazon s3 bucket. But I am not able to upload using Jquery file upload plugin. I am getting error message that Key is not found.

 $(function () {
    $('#fileupload').each(function () {

        var form = $(this)

        $(this).fileupload({
            url: '@Model.FormAction',
            type: 'POST',
            autoUpload: true,
            dataType: 'xml',
            formData: 
                {

                    AWSAccessKeyId: "@Model.AWSAccessKey",                   
                    acl: "@Model.Acl",                                        
                    policy: "@Model.Base64EncodedPolicy",                                  
                    signature: '@Model.Signature',                            
                    success_action_status: "201",
                    key: '@Model.FileID'
                },
            done: function (event, data) {
                var url = $(data).find('Location').text()

                $('#Feedback').val(url)
            }
        });
    });
});
</script>

Is there any other plugin available for file upload with sample code ?

Pas de solution correcte

Autres conseils

Have a look at this answer I posted recently: https://stackoverflow.com/a/22085396/148998

Do you have to use javascript to post it to amazon? It might be easier to use server side code, amazon provide a pretty decent Api which is available via Nuget

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top