[英]Request header field Cache-Control is not allowed
I am having a small issue, with sending users uploaded images to our api domain I am using the dropzone.js, however it seems that while it is not an error with the HTML code, there is an error with the .htaccess
code. 我遇到一个小问题,将用户上传的图像发送到我们的api域,我使用的是dropzone.js,但是似乎HTML代码不是错误,但
.htaccess
代码却有错误。
While I don't think there is anything wrong with my HTML code I'll paste it below. 虽然我认为我的HTML代码没有任何问题,但是我将其粘贴在下面。
HTML code: HTML代码:
<div class="mdl-grid mdl-cell mdl-cell--11-col">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<div id="profile" class="dropzone">
</div>
</div>
</div>
<script type="text/javascript">
var mydrop = new Dropzone("div#profile", {
url: "https://APISITEDOMAIN.COM/",
paramName: "file",
maxFiles : 1,
uploadMultiple: false,
addRemoveLinks : false,
acceptedFiles: 'image/*',
autoProcessQueue: true,
init: function() {
var submitButton = document.querySelector("#act-on-upload")
myDropzone = this;
submitButton.addEventListener("click", function() {
myDropzone.processQueue();
});
myDropzone.on("addedfile", function(file) {
if (!file.type.match(/image.*/)) {
if(file.type.match(/application.zip/)){
myDropzone.emit("thumbnail", file, "path/to/img");
} else {
myDropzone.emit("thumbnail", file, "path/to/img");
}
}
});
myDropzone.on("complete", function(file) {
myDropzone.removeFile(file);
});
},
});
console.log( mydrop.dropzone );
</script>
On the API server I have added the following to .htaccess 在API服务器上,我已将以下内容添加到.htaccess中
ErrorDocument 403 http://SITE.xyz/
RewriteEngine On
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
However I am still getting the following error 但是我仍然收到以下错误
XMLHttpRequest cannot load https://apisite.com Request header field Cache-Control is not allowed by Access-Control-Allow-Headers in preflight response.
Try to add the following properties to your dropzone object 'mydrop': 尝试将以下属性添加到您的dropzone对象“ mydrop”:
headers: {
'Cache-Control': null,
'X-Requested-With': null,
}
According to W3's documentation on CORS with preflight , you need to "include an Access-Control-Request-Method header with as header field value the request method (even when that is a simple method )". 根据W3关于带有preflight的CORS的文档 ,您需要“包括一个Access-Control-Request-Method标头,并将请求方法作为标头字段值(即使这是一个简单的方法 )”。
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.