2017-09-28 12 views
0

클라이언트의 파일에서 이미지를 thumbnail이라는 Wakanda 엔티티의 이미지 속성 값으로 업로드하려고 시도하고 있습니다. 나는이 문서에서 the example를 사용하고 있지만 브라우저에서 다음과 같은 오류를 받고 있어요 :Wakanda 서버의 엔티티 속성에 대한 이미지 업로드

자원을로드하지 못했습니다 : 서버가 (찾을 수 없음) (404)의 상태로 응답 http://localhost:8081/Artwork(016A8CCE202847FA87DF78A27353121D)/thumbnail $ rawPict = 이미지/

ds.Artwork.find(artworkId).then(artwork => { 
    return artwork.thumbnail.upload(this.testFileInputElement.files[0]); 
}).catch(e => { 
    debugger; 
}); 

이 오류가 캐치 e 인수에 반환됩니다

JPEG

다음은 내 코드입니다. 아트웍 엔티티가 제대로 검색되었는지, 썸네일 속성이 upload 메쏘드인지 그리고 this.testFileInputElement.files[0]이 적절한 File 객체인지 확인했습니다.

+0

이 버그는 Wakanda의 2.3.0 릴리스에서 수정되었습니다. – hamzahik

답변

0

업데이트 : Wakanda Github에 버그를 제출했으며 승인되었습니다. 버그 상태 there을 추적 할 수 있습니다. 그동안 아래 제공된 해결 방법을 자유롭게 사용하십시오.

테스트를 거쳐 404 오류가 발생했습니다. 이것은 버그 인 것 같습니다. 올바른 파일 업로드 URL은 baseURL과 dataclass 이름 사이에 http://localhost:8081/rest/Artwork(016A8CCE202847FA87DF78A27353121D)/thumbnail? $ rawPict = image/jpeg와 같이 "/rest"이어야합니다. 이 수정 근무

MediaBaseService._buildUri = function (dataClassName, entityKey, attributeName) { 
     return '/rest/' + dataClassName + '(' + entityKey + ')' + '/' + attributeName; 
}; 

:

은 내가 찾은 수정은 웹/node_modules/wakanda 클라이언트에서 "wakanda-client.no-primise.js"의 3454 라인하기 위해 "/ 휴식"을 추가하는 것입니다 나를. 버그와 잠재적 인 문제를 팀에보고 할 것입니다. enter image description here

0

REST upload()을 사용하여 이미지를 업로드 해 보았습니까?

프로덕션 용도로는 사용하지 않는 것이 좋지만 이미지를 해당 엔터티에 업로드 할 수 있는지 여부를 테스트해야합니다.

나 자신의 API를 가지고 있으므로 아래에서 개발 한 코드를 사용해 볼 수도 있습니다.

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; 
} 

그런 다음 클라이언트 측 POST 메시지에이 같은 것을 (모듈이 '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(); 

} 

모듈에서하는 index.js 파일 설치 'http://localhost:8081/api/v1/file/uploadFile'을 메시지 본문에있는 이미지와 비교하십시오.

원한다면 사용해도 좋지만 주로 이미지를 파일에 업로드 할 수 있는지 테스트하는 한 가지 방법으로 포함되어 있습니다.