Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I'm getting an error while trying to upload a document in Confluence Macro page

getting Like Access to XMLHttpRequest at 'https://edm-files-documents-service-api.dev.cloud.ebmpapst.com/api/confluence/document' from origin 'http://vmr2-delphi24x:1990' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
batch.js?devtoolbar=true&hostenabled=true&locale=en-US&user-logged-in=true:223 POST https://edm-files-documents-service-api.dev.cloud.ebmpapst.com/api/confluence/document net::ERR_FAILED

 

var getLoc = function() {
var lang;

if (navigator.languages) {
lang = navigator.languages[0];
} else if (navigator.userLanguage) {
// IE only
lang = navigator.userLanguage;
} else {
lang = navigator.language;
}

return lang;
};
AJS
.$(document)
.ready(
function() {
if (!FileReader.prototype.readAsBinaryString) {
FileReader.prototype.readAsBinaryString = function (fileData) {
var binary = "";
var pt = this;
var reader = new FileReader();
reader.onload = function (e) {
var bytes = new Uint8Array(reader.result);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) {
binary += String.fromCharCode(bytes[i]);
}
//pt.result - readonly so assign binary
pt.content = binary;
pt.onload();
}
reader.readAsArrayBuffer(fileData);
}
}
var regDe = /de/;
var user = document.getElementById("confuser").value.toUpperCase();
console.log(user);
if (typeof (AJS.I18N) !== 'undefined') {
console
.log(AJS.I18n
.getText("ebmpapst-confluence-macro.edm-dokumente.genlink.multiple.select"));
}
var locale = getLoc();
var dropDict = {};
if (locale !== undefined) {
if (regDe.test(locale)) {
dropDict = {
"default" : "Oder ziehen sie eine Datei hinein um sie hochzuladen",
"fallback" : "Ihr Browser unterstützt das Hochladen von Dateien über Drag & Drop nicht.",
"cancel" : "Abbrechen",
"removeFile" : "Datei aus Liste entfernen.",
"cancelUpload" : "Sind sie sicher, dass sie diesen Upload abbrechen wollen ?",
"maxFile" : "Sie können nur eine Datei pro Verlinkung hochladen."
};
} else {
dropDict = {
"default" : "Or drop a file in here to upload it",
"fallback" : "Your browser does not support drag & drop file uploading!",
"cancel" : "cancel",
"removeFile" : "Remove file from list",
"cancelUpload" : "Are you sure that you want to cancel this upload ?",
"maxFile" : "You can only upload one file per link generation."
};
}
} else {
dropDict = {
"default" : "Or drop a file in here to upload it",
"fallback" : "Your browser does not support drag & drop file uploading!",
"cancel" : "cancel",
"removeFile" : "Remove file from list",
"cancelUpload" : "Are you sure that you want to cancel this upload ?",
"maxFile" : "You can only upload one file per link generation."
};
}
if (typeof (Dropzone) !== 'undefined') {
var userInput = document.getElementById('user');
userInput.value = user;
Dropzone.options.dropUpload = {
paramName : "file",
uploadMultiple : false,
addRemoveLinks : true,
maxFiles : 1,
dictDefaultMessage : dropDict['default'],
dictFallbackMessage : dropDict['fallback'],
dictCancelUpload : dropDict['cancel'],
dictRemoveFile : dropDict['removeFile'],
dictCancelUploadConfirmation : dropDict['cancelUpload'],
dictMaxFilesExceeded : dropDict['maxFile'],
init : function() {
this.on('addedfile',function(file) {
var reader = new FileReader();
reader.onload = function(e) {
if (!e) {
var data = reader.content;

console.log("pass-1")
}
else {
var data = e.target.result;

console.log("pass-2")
}
var settings = {
async: true,
crossDomain: true,
//url: "http://10.149.6.181/cgi-bin/wsDocument.dll/TDocument/CreateDocument/",
url : "https://edm-files-documents-service-api.dev.cloud.ebmpapst.com/api/confluence/document",
type: "POST",
headers: {
"Access-Control-Allow-Origin":"*",
"Access-Control-Allow-Methods": "GET,POST,PUT,DELETE",
"Access-Control-Allow-Headers": "Content-Type",
"cache-control": "no-cache"
},

processData: false,
dataType: "json",
contentType: "application/json; charset=utf-8",

data: JSON.stringify({
"user": user,
"subject": file.name,
"file": btoa(data),
"remark": file.name.split('.').pop().toLowerCase()
}),

success:function(data) {
var id = data.result[0].docNo;
AJS.$('#dokid').val(id)
AJS.$("#search-form").submit();

console.log("Success")
},
error:function(err) {
console.log(err)
console.log("fail")
}
}

AJS.$.ajax(settings).done(function (response) {
console.log(response);
});
};
reader.readAsBinaryString(file);
});
}
};
}
});

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

Confluence Mythbusters: Does Atlassian even use Confluence?

Hi, Confluence collaborators! As part of #Confluence-Collaboratory month, we’ve created a very special Mythsbusters segment, where we're dive into an interesting myth and uncover the truth behind i...

1,683 views 7 31
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you