我尝试用S3设置FineUploader,并且当我启用分块时,我遇到了CORS设置问题
我在每个PUT请求上都收到此错误:
跨源请求被阻止:“相同源策略”不允许在[AWS SOURCE]处读取远程资源。 (原因:CORS请求未成功。)
我在S3存储桶上启用了cors:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<ExposeHeader>ETag</ExposeHeader>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
我的本地脚本部分是
<script language="JavaScript">
var s3Uploader = new qq.s3.FineUploader({
debug: true,
element: $('fine-uploader-s3-1'),
template: 'qq-template-s3',
multiple: false, // no multiple uploads allowed
request: {
endpoint: "https://BUCKET.s3.amazonaws.com",
accessKey: "PUBLIC_KEAY",
params: {
category: "synnex-exhibitor-portal-test"
}
},
signature: {
// version: 4,
endpoint: "/fineUploader/s3/endpoint-cors.php"
},
uploadSuccess: {
endpoint: "/fineUploader/s3/endpoint-cors.php?success",
},
iframeSupport: {
localBlankPagePath: "/fineUploader/s3/success.html"
},
retry: {
enabledAuto: true,
showButton: true
},
cors: {
expected: true
},
chunking: {
enabled: true,
concurrent: {
enabled: true
}
},
resume: {
enabled: true
},
deleteFile: {
enabled: true,
method: "POST",
endpoint: "/fineUploader/s3/endpoint-cors.php"
},
callbacks: {
onComplete: function(id, name, response) {
console.log('Completed for ID: %s, with name: %s', id, name);
}
}
});
</script>
我可以上传超出分块大小的文件。
我的问题是我如何应对OPTIONS请求?我试图在Apache中设置标头以始终发送:
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Allow-Origin: http://MY.SERVER.COM
我还尝试在服务器的根文件夹或fineUploader的根文件夹(我的原始页面位于此文件夹)中设置一个.htaccess文件
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ - [ENV=PREFLIGHT:true]
Header always set Access-Control-Allow-Origin: "http://soba.tokyo.tequila.jp" env=PREFLIGHT
Header always set Access-Control-Allow-Methods: "POST" env=PREFLIGHT
Header always set Access-Control-Allow-Headers: "Content-Type" env=PREFLIGHT
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=204,L]
但是由于这里没有OPTIONS回调,因此永远不会发送此标头。
我从没在服务器端脚本中看到任何方法OPTIONS调用,也从未在脚本源于服务器的任何其他请求中看到任何方法。我的本地服务器是PHP 7.2的Apache
有关如何或在何处正确响应的任何帮助
更多详细信息在这里:https://github.com/FineUploader/fine-uploader/issues/2031