Question

I'm uploading an image to s3 using ajaxform. The image is getting uploaded to s3 but I'm not able to get the response from the S3 server. I need the response to notify the user that the upload is complete. According to me,the ajax form jquery plugin is working fine because If I replace this form by another form where the action url is of the same server as of the application and not of s3, its coming in the success(but i cant do this if I have to upload the image to s3). I've tried events other than success also like complete, error, fail etc. But It's coming nowhere. Here's is the relevant part of the code:

<script>
        function submitMyForm(){
            $("#myForm").ajaxForm({
            success : function(result){
                alert(result);
            }
             }).submit();
        }
</script>
<form id="myForm" action="https://my-bucket-name.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
      <input type="hidden" name="key" value="${filename}">
      <input type="hidden" name="AWSAccessKeyId" value="my-access-key-id"> 
      <input type="hidden" name="acl" value="private"> 
      <input type="hidden" name="success_action_redirect" value="">
      <input type="hidden" name="policy" value="my_policy">
      <input type="hidden" name="signature" value="my_signature">
      <input type="hidden" name="Content-Type" value="image/jpeg">
      File to upload to S3: 
      <input name="file" type="file"> 
</form>
<button onclick="submitMyForm()">Submit</button>

In console I'm getting this: [jquery.form] state = complete. Can I somehow use this to capture the callback of the ajax form. Too much confused I am right now. Please help.

Was it helpful?

Solution

You should avoid using ajax while submitting to S3 as the form action doesn't belong to your server and that's why there are problems in getting the success message back from the server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top