Hi All,
We are trying to upload a file in feeds side panel. But for some reason its not working.
I looked at threads and tried both ways by converting the body to asString() and asArrayBuffer(). I am still getting error "$.request.entities[0] is undefined".
XSJS - Unable to send mail with pdf attachment | SCN
How to handle POST request in an xsjs file?
My code is as follows:
onFileUploadClick: function(event, data) {
this.oFileUploadButton = event.oSource;
this.oFileUploader = data[0];
var oDescriptionInput = data[1];
var oTitleInput = data[2];
var fileName = this.oFileUploader.getValue();
var description = oDescriptionInput.getLiveValue();
var title = oTitleInput.getLiveValue();
if (this.getCurrentGroupID() === null) {
this.showErrorMessage("Please choose a valid group.");
return;
}
//on upload start:
this.addBusy(this.feedView.oUploadFileContainer);
this.oFileUploadButton.setEnabled(false);
//this.oFileUploader.setEnabled(false); FILE UPLOADER STOPS WORKING IF DISABLED
this.oFileUploader._bUploading = true;
var url = "/sap/sop/sopfnd/services/collaboration/CollaborationServices.xsjs" +
"?objName=CollaborationFeed" +
"&action=handleFileUpload" +
"&fileName=" + fileName +
"&description=" + description +
"&groupID=" + this.getCurrentGroupID();
var self = this;
var file = jQuery.sap.domById("feedEntryFileUploader-fu").files[0];
var reader = new FileReader();
reader.readAsBinaryString(file);
reader.onload = function(event) {
var contents = event.target.result;
// var contents = event.target.result.asArrayBuffer();
console.log(contents);
$.ajax({
type: "POST",
url: url,
cache: false,
data: contents,
contentType: false,
processData: false,
//headers: {"slug": fileName},
success: self.onFileUploadComplete,
error: self.onFileUploadError,
context: self
}).always(function(response) {
self.oFileUploadButton.setEnabled(true);
self.oFileUploader.setEnabled(true);
});
};
var formEle = jQuery.sap.domById("feedEntryFileUploader");
var form = $(formEle).find("form")[0] ;
var fd = new FormData(form);
console.log("onFileUploadClick: " + url);
this.oFileUploader.setUploadUrl(url);
this.oFileUploader.upload();
}
Any help would be much appreciated.
Thanks & Regards
Uday