Hi Experts,
I was trying to send the file to open text server.
1) I am getting the token correctly.
2) while sending the file, it's saying Bad request.
3) I am using SAP UI5, in my project.
Please find below the code which i have used, and guide me here.
Thanks in Advance.
var file = jQuery.sap.domById("uploadId" + "-fu").files[0] ;// just like document.getElementById
console.log(file);
var fd = new FormData();
fd.append( "type", "144" );
fd.append( "parent_id", "xxxx" );
fd.append( "name", file.name );
fd.append("file_content_type",file.type);
fd.append( "file", file );
console.log("fd:"+fd);
console.log("fd:"+JSON.stringify(fd));
var token = undefined;
$.ajax({
type: "POST",
url: "http://xxxxxxxxxxxxx/xxxxx/cs.exe/api/v1/auth",
data: { username:"xxxxxxxxxxx", password:"xxxxxxx" },
async: false,
success : function(data) {
token = data.ticket;
alert("token:"+token);
alert('getNodeInfo')
if(token) {
$.ajax({
type: "GET",
url:
"http://xxxxxxxxxxx/xxxxxx/cs.exe/api/v1/nodes/xxxxx",
headers:{"OTCSTICKET":token
},
async: false,
success : function(data) {
//console.log(JSON.stringify(data));
},
error : function(e, s, t) {
// On error it comes here
alert("ERROR:"+JSON.stringify(e));
}
});
$.ajax({
type: "POST",
url:
"http://http://xxxxxxxxxxx/xxxxxx/cs.exe/api/v1/nodes/xxxxx",
beforeSend: function( xhr ) {
xhr.setRequestHeader( "otcsticket",
token),
xhr.overrideMimeType( "multipart/form-
data")
},
data:fd,
async: false,
contentType: false,
processData: false,
success : function(data) {
console.log(JSON.stringify(data));
},
error : function(e, s, t) {
// On error it comes here
alert("ERROR:"+JSON.stringify(e));
}
});
}
}
});