Have you tried uploading the image using REST upload()?
I wouldn't recommend it for production use, but it should test whether you can upload an image to that entity.
You could also try the code below which I developed because I have my own API.
function uploadFile(request,response){
response.contentType = 'application/json';
var i,
j=1,
nameTemp,
img,
files=[],
returnJSON = [],
newName,
folder,
filePath;
folder = getFolder('path')+'/database/data/uploads/'
for(i=0;i<request.parts.length;i++){
filePath = folder + request.parts[i].fileName.replace(/\s/g,'_');
files.push(new File(filePath));
returnJSON[i]={};
returnJSON[i].name = request.parts[i].name
returnJSON[i].value = request.parts[i].fileName;
var documentName = request.parts[i].name
//saveFileToData(filePath, imgName);
}
for(i=0;i<files.length;i++){
j=1;
var filePath;
if(!files[i].exists){
myBinaryStream = BinaryStream(files[i],'Write');
myBinaryStream.putBlob(request.parts[i].asBlob);
myBinaryStream.close();
saveFileToData(files[i].path, files[i].name);
}else{
while(files[i].exists){
nameTemp = files[i].name.replace(/\s/g,'_');
filePath = folder+files[i].nameNoExt.replace(/\s/g,'_')+j+'.'+files[i].extension
files[i] = new File(filePath);
newName = files[i].name;
if(files[i].exists){
files[i] = new File(folder+nameTemp);
}
j++;
}
myBinaryStream = BinaryStream(files[i],'Write');
myBinaryStream.putBlob(request.parts[i].asBlob);
myBinaryStream.close();
returnJSON[i].value = files[i].name; //this is the fileName
saveDocumentToData(files[i].path, nameTemp);
}
}
return returnOK(returnJSON);
}
function returnOK (returnJSON) {
returnJSON = JSON.stringify(returnJSON);
return returnJSON;
}
function saveDocumentToData(path, documentName){
var theDocumentFile = loadFile(path);
var theDocument = theDocumentFile.asPicture;
var documentEntity = ds.Document.createEntity();
documentEntity.File = path;
documentEntity.name = FileName;
documentEntity.save();
}
Then install it with an index.js file in a module (in my case the module is called 'api') something like this:
exports.postMessage = function (message) {
var serviceFile = new File(module.filename);
var parent = serviceFile.parent;
var fileFile = new File(parent, 'file-handlers.js');
switch (message.name){
case 'httpServerDidStart':
httpServer.addRequestHandler("^/api/v1/file", fileFile.path, "fileHandler");
break;
case 'httpServerWillStop':
httpServer.removeRequestHandler("^/api/v1/file", adminFile.path, "fileHandler");
break;
}
Then on the client side POST a message to 'http://localhost:8081/api/v1/file/uploadFile with the image in the body of the message.
You're welcome to use it if you want but I mainly included as one way of testing if you can upload the image to the file.