0

私はcordovaファイル転送プロトコルを使用し、ダウンロード機能を使用してbase-64イメージをダウンロードしました。「 https://upload.wikimedia.org/wikipedia/commons/4/4a/Logo_2013_Google.png 」のようなリモートサーバーパスを配置するとダウンロードされますが、base-64イメージパスをファイルパスに配置するとダウンロードされません。base-64 変換についてはわかりません。助けてください。

----私のコードは以下です----

  function download(){
        var imageData = image.src;
        imageData = imageData.replace('data:image/png;base64,', '');

        var d = new Date();
        var imageName = "sample" + d.getTime() + ".png";

        //var filepath = encodeURI("https://upload.wikimedia.org/wikipedia/commons/4/4a/Logo_2013_Google.png");
        var filepath = encodeURI(imageData);

        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
            fileSystem.root.getFile(imageName, { create: true, exclusive: true }, 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;
                var fileTransfer = new FileTransfer();
                fileTransfer.download(remoteFile, localPath, function (newFileEntry) {
                    // successful download, continue to the next image
                    console.log('successful download');
                },
                function (error) { // error callback for #download
                    console.log('Error with #download method.', error);
                });
            });
        })

    })
}
}

前もって感謝します。

4

1 に答える 1

1

私は自分の質問の解決策を見つけました。

まず、base64 イメージをファイル ストリームに変換し、Web サービスを使用してサーバー上にイメージを作成し、サーバー上にイメージをアップロードして、そのサーバー パスを取得し、cordova filetransfer を使用してダウンロードします。

私のコードは以下です

=> base64 イメージをイメージに変換するための Web サービス コード

string strImg = imageData.imageData;
   string fullName = "d:\\uploadimages";
   FileStream fs = new FileStream(fullName, FileMode.Create);
   BinaryWriter bw = new BinaryWriter(fs);

   byte[] data = Convert.FromBase64String(strImg);

   bw.Write(data);
   bw.Close();

=>モバイルで画像をダウンロード

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

            })
}
于 2016-02-23T07:43:40.147 に答える