Im trying the dropzone to my Dropbox API and I was wondering how to pass the value of my ajax to my form action = "*"
Because when I removed the action it said Dropzone : Uncaught Error: No URL provided
But when I put my specific endpoint it said Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin
' but theres a Authorization in my ajax headers
This is my codes
<html>
<script src='//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">
<form action="https://content.dropboxapi.com/2/files/upload" type="file" id="files" name="files[]" multiple class = "dropzone">
</form>
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// files is a FileList of File objects
for (var i = 0, file_name; file_name = files[i]; i++) {
$.ajax({
url: 'https://content.dropboxapi.com/2/files/upload',
type: 'post',
data: file_name,
processData: false,
contentType: 'application/octet-stream',
headers: {
"Authorization": "Bearer ACCESS TOKEN",
"Dropbox-API-Arg": '{"path": "/' + file_name.name + '","mode": "add"}'
},
success: function (data) {
alert('The file has been uploaded!');
console.log(data);
},
error: function (data) {
console.log(data);
}
})
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</html>