Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 客户端上传到S3。否';访问控制允许原点';标题_Ajax_Amazon S3_Jquery File Upload - Fatal编程技术网

Ajax 客户端上传到S3。否';访问控制允许原点';标题

Ajax 客户端上传到S3。否';访问控制允许原点';标题,ajax,amazon-s3,jquery-file-upload,Ajax,Amazon S3,Jquery File Upload,我一直在尝试根据我找到的几个示例为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 ac

我一直在尝试根据我找到的几个示例为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>

好吧,我真傻。是在错误的桶上工作

你们在哪里能做到?我已经试了很多次了,但仍然会出错。
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)