Use AWS S3 success_action_redirect policy using XHR

I use signed POST to upload a file directly to Amazon S3. I had some problems with the policy signatures using PHP, but finally it was fixed and here is the sample code .

This xhr request is sent to javascript and I am waiting for a response from amazon. First I used success_action_status , setting it to 201 to get an XML response.

What I would like to do is use success_action_redirect to call a script on my server to create a record in the database.

The reason I can create an entry in the database, and if something wrong happens at this point, I can immediately send an error message. It also saves me another ajax request to my server.

So, I tried to set this by pointing success_action_redirect to http:\\localhost\callback.php , where I have a script that is waiting for some parameters.

But it looks like this script is never called, and the response of xhr.send() empty.

I think this is a cross browser issue, and I wonder if it is possible to use jsonp somehow to pass this? Any ideas?

UPDATE

Apparently, xhr should be redirected initially, so it should work, but when I specified success_action_redirect , it returns error Server responded with 0 code.

At first, I thought this was because the redirect URL was on my local server, so I changed it to an available server, but no chance.

Does anyone know why it is returning this error message?

+6
source share
1 answer

I also run into this problem. It seems no one has a solution for this as possible, the best workaround I have found is something like this . It seems that the only workaround is the second xhr request to execute the callback manually. so

success_action_status

. With it, you will get a 201 response if the download was successful, and you can run a second request for the actual callback. For me, this seems like the only possible solution at the moment.

Any other solutions?

0
source

Source: https://habr.com/ru/post/943872/


All Articles