2017-04-07 2 views
1

내 응용 프로그램에서 ionic 2 파일 전송 네이티브 플러그인을 사용하여 서버에서 Sample.csv 파일을 다운로드하고 있습니다.'전송'속성에 '다운로드'속성이 없습니다. in ionic 2 FileTransfer

오류 메시지가 아래에 직면 :

재산권 '다운로드'형 '전송'에 존재하지 않습니다.

const fileTransfer = new Transfer(); 
    let url = 'url to the server file'; 
    console.log(url); 

    fileTransfer.download(url, cordova.file.dataDirectory + 'Sample.csv').then((entry) => { 

     console.log('download complete: ' + entry.toURL()); 
    }, (error) => { 
        console.log("No file to download"); 
    }); 

콘솔에서 코도 바를 정의하지 않았습니다.

아무도 도와 줄 수 있습니까?

답변

1

가져와야합니다.

import { Transfer, FileUploadOptions, TransferObject } from '@ionic-native/transfer'; 
import { File } from '@ionic-native/file'; 

그런 다음에 주입하십시오.

constructor(private transfer: Transfer, private file: File) { } 

다음과 같이 선언하십시오.

const fileTransfer: TransferObject = this.transfer.create(); 

다음과 같이 사용하십시오.

// Download a file: 
fileTransfer.download(..).then(..).catch(..); 

official doc here을 참조 할 수 있습니다.

+0

감사합니다. 속성 '다운로드'가 '전송'유형에 없습니다. 문제가 해결되었지만 코드 바가 정의되지 않은 콘솔에 여전히 오류 메시지가 표시됩니다. –

+0

브라우저에서 Cordova 플러그인을 실행할 수 없습니다. 장치 또는 에뮬레이터를 사용해야합니다. – Sampath

+0

나는 ionic-view app에 파일을 다운로드하지 않고 업로드하여 'my app'을 시도했다. 다운로드 버튼을 클릭해도 아무런 변화가 없습니다. –