모바일 장치 (Android, iPhone, Windows)에서 Base-64 소스 이미지를 다운로드하고 장치 전화 메모리에 저장하는 방법

카필 다르지

telerik 앱 빌더를 사용하여 하나의 샘플 앱을 만들었습니다. 하나의 간단한 뷰와 하나의 js 파일을 만들고 뷰에서 하나의 이미지를 렌더링하고 base-64로 변환했습니다. 이 이미지를 다운로드하고 자바 스크립트를 사용하여 기기 내부 저장소에 저장해야합니다.

javascript의 download.js 플러그인을 사용했는데 다운로드 기능이 작동하지 않습니다. 제안 해주세요.

내 코드는 다음과 같습니다.

function (image)
{
var imageData = image.src;
imageData = imageData.replace('data:image/png;base64,', '');
download(imageData, "image11111", "image/png");
}
카필 다르지

내 질문에 대한 답을 찾았습니다.

cordova filetransfer를 사용하여 모바일 장치에서 이미지를 다운로드 할 수 있습니다.

function download()
{
    var filepath = encodeURI("http://www.telerik.com/sfimages/default-source/logos/app_builder.png"),
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
                fileSystem.root.getFile("sample.jpg", { create: true, exclusive: false }, function (fileEntry) {

                    // get the full path to the newly created file on the device
                    var localPath = fileEntry.fullPath;

                    // massage the path for android devices (not tested)
                    if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
                        localPath = localPath.substring(7);
                    }

                    // download the remote file and save it
                    var remoteFile = filepath;
                    //loadingOverlay.displayLoading("Image will be save on your device.");

                    var fileTransfer = new FileTransfer();
                    fileTransfer.download(remoteFile, localPath, function (newFileEntry) {
                        // successful download, continue to the next image
                        var dwnldImagePath = newFileEntry.fullPath;
                        console.log('successful download');

                    },
                    function (error) { // error callback for #download
                        console.log('Error with #download method.', error);

                    });
                });
                function(error) { // error callback for #getFile
                    console.log('Error with #getFile method.', error);
                });

            })
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관