1
我一直在嘗試拋出一個基於S3的客戶端上傳表單基於我發現的幾個例子,但我似乎無法解決我的錯誤得到的OPTIONS請求:客戶端上傳到S3。沒有'訪問控制允許來源'標頭
XMLHttpRequest cannot load https://s3.amazonaws.com/myApp. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
從我的理解,如果我沒有包括在我的請求Origin標,但是這應該被觸發...
Host:s3.amazonaws.com
Origin:http://localhost:3000
任何人都有一個想法,爲什麼標題可能沒有包含在響應中?下面是一些更多的細節 CORS配置
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://localhost:3000</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
的CoffeeScript
jQuery ->
$('#fileupload').fileupload
add: (e, data) ->
types = /(\.|\/)(gif|jpe?g|png)$/i
file = data.files[0]
if types.test(file.type) || types.test(file.name)
data.context = $($.tmpl("template-upload", file))
$('#fileupload').append(data.context)
data.submit()
else
alert("#{file.name} is not a gif, jpeg, or png image file")
progress: (e, data) ->
if data.context
progress = parseInt(data.loaded/data.total * 100, 10)
data.context.find('.bar').css('width', progress + '%')
done: (e, data) ->
file = data.files[0]
domain = $('#fileupload').attr('action')
path = $('#fileupload input[name=key]').val().replace('${filename}', file.name)
to = $('#fileupload').data('post')
content = {}
content[$('#fileupload').data('as')] = domain + path
$.post(to, content)
data.context.remove() if data.context # remove progress bar
fail: (e, data) ->
alert("#{data.files[0].name} failed to upload.")
console.log("Upload failed:")
console.log(data)
大聲笑。我也犯了同樣的錯誤。 – Musaffa 2015-01-31 21:14:37
你們能夠實現它的地方?我一直在嘗試很多,但仍然出現錯誤。 – 2015-07-21 07:22:25