Haben Sie versucht, das Bild mit REST upload() hochzuladen?
Ich würde es nicht für den Produktionseinsatz empfehlen, aber es sollte testen, ob Sie ein Bild auf diese Entität hochladen können.
Sie könnten auch den Code unter dem ich entwickelt habe, weil ich meine eigene API habe.
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();
}
Dann installieren Sie es mit einer index.js Datei in einem Modul so etwas wie diese (in meinem Fall das Modul ‚api‘ genannt wird):
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;
}
Dann auf der Client-Seite eine Nachricht zu 'http://localhost:8081/api/v1/file/uploadFile mit dem Bild im Nachrichtentext.
Sie können es gerne verwenden, wenn Sie wollen, aber ich habe hauptsächlich als eine Möglichkeit des Testens aufgenommen, wenn Sie das Bild in die Datei hochladen können.
Dieser Fehler wurde in der Version 2.3.0 von Wakanda behoben – hamzahik