martinklepsch / s3-beam

🚀 direct-to-S3 uploading using ClojureScript
Eclipse Public License 1.0
92 stars 17 forks source link

Errors when uploading file to S3 #3

Closed yayitswei closed 9 years ago

yayitswei commented 9 years ago

Hi Martin, thanks for making s3-beam.

I'm getting some errors when uploading to S3. Some files yield this error:

POST https://my-bucket.s3-eu-west-1.amazonaws.com/ net::ERR_CONNECTION_RESET

And some this error:

XMLHttpRequest cannot load https://my-bucket.s3-eu-west-1.amazonaws.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
client.cljs:37 Uncaught TypeError: Cannot read property 'getElementsByTagName' of null(anonymous function) @ client.cljs:37goog.events.EventTarget.fireListeners @ eventtarget.js:285goog.events.EventTarget.dispatchEventInternal_ @ eventtarget.js:382goog.events.EventTarget.dispatchEvent @ eventtarget.js:197goog.net.XhrIo.dispatchErrors_ @ xhrio.js:666goog.net.XhrIo.onReadyStateChangeHelper_ @ xhrio.js:808goog.net.XhrIo.onReadyStateChangeEntryPoint_ @ xhrio.js:748goog.net.XhrIo.onReadyStateChange_ @ xhrio.js:732

Here's the S3 configuration I'm using:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

Am I missing something?

martinklepsch commented 9 years ago

Are you sure the name of your bucket is my-bucket?

POST https://**my-bucket**.s3-eu-west-1.amazonaws.com/ net::ERR_CONNECTION_RESET

yayitswei commented 9 years ago

It's not, I changed the name of the bucket for privacy (since at the moment it has a very permissive policy).

martinklepsch commented 9 years ago

Your CORS configuration looks alright.

Is your bucket located in s3-eu-west-1? In 0.1.0 this was not customisable. If your bucket is in another zone I recommend you update to 0.2.0 which introduces an additional aws-zone parameter. See the changelog in the Readme for details.

yayitswei commented 9 years ago

Thanks for your update, I got it working!

For the bucket location, I had to use the generic s3 instead of s3-eu-west-1. Do you know why my bucket didn't have a zone attached to it?

Also, I had to add in

(extend-type js/HTMLCollection
  ISeqable
  (-seq [array] (array-seq array 0)))

to work around the "HTMLCollection is not seqable" error in the line (first (.getElementsByTagName (.getResponseXml (.-target res)) "Location")).

martinklepsch commented 9 years ago

Do you know why my bucket didn't have a zone attached to it?

No. As far as I understand buckets must be associated with a region.

(extend-type js/HTMLCollection
  ISeqable
  (-seq [array] (array-seq array 0)))

Good catch. I probably had this in the project I was using it so I didn't notice that it'd break without that extend-type statement.

It's probably a good idea to use (aget (.getElements... ) 0) here instead of first.

PR welcome! :smile:

martinklepsch commented 9 years ago

You can now use [org.martinklepsch/s3-beam "0.2.1"] which uses aget instead of first.

https://github.com/martinklepsch/s3-beam/commit/fa3238968f9e059968bf0731ed488fa50e437502

yayitswei commented 9 years ago

Thanks! You beat me to the pull request :)