2017-11-19 3 views
1

메소드 호출을 사용하여 유성에 대한 파일 업로드를 구현하려고합니다.메소드 호출을 사용하여 유성 서버에 파일 업로드하기

이 유성애 패키지를 사용하고 있습니다 : https://atmospherejs.com/ostrio/files.

나는 클라이언트 측에서 아무런 문제가 없다. (나는 base64 인코딩 형식으로 파일을 보낼 수있다.) 서버 측에서이 함수를 구현하려고합니다 : https://github.com/VeliovGroup/Meteor-Files/blob/master/docs/write.md

이 오류가 발생합니다. 다음과 같이 처음에, FilesCollection의 인스턴스와 유사한 Images를 인스턴스화해야합니다 lib 디렉토리 문서에 따르면

export const insertImage = new ValidatedMethod({ 
    name: 'images.insert', 
    validate: new SimpleSchema({ 
    file: { type: String }, 
    }).validator(), 
    run({ file }) { 
    Images.write(file, { 
     fileName: 'sample.png', 
     type: 'image/png', 
    }, function (error, fileRef) { 
     if (error) { 
     throw error; 
     } else { 
     console.log(`${fileRef.name} is successfully saved to FS. _id: ${fileRef._id}`); 
     } 
    }); 
    }, 
}); 

답변

0

:

다음
Error during upload: TypeError: Images.write is not a function 

서버에서 내 방법의 코드

https://github.com/VeliovGroup/Meteor-Files#api-overview-full-api

import { FilesCollection } from 'meteor/ostrio:files'; 

const Images = new FilesCollection({ 
    collectionName: 'Images', 
    allowClientCode: false, // Disallow remove files from Client 
    onBeforeUpload(file) { 
    // Allow upload files under 10MB, and only in png/jpg/jpeg formats 
    if (file.size <= 10485760 && /png|jpg|jpeg/i.test(file.extension)) { 
     return true; 
    } else { 
     return 'Please upload image, with size equal or less than 10MB'; 
    } 
    } 
}); 

생성자 매개 변수에 대한 자세한 내용은 내가이 구문을 사용했다

+0

내가 이미했다. –

+0

이미 이미지 컬렉션을 서버에서 인스턴스화하고 서버에서 사용했습니다. 그러나 클라이언트에서 인스턴스화하는 것은 나의 유스 케이스가 아니다. 내 문제에 대한 해결책을 찾았습니다. 나는 답으로 게시 할 것이다. 고맙습니다 ! –

관련 문제