Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-7927

[WP8][cordova-plugin-file] Unable to write a binary file.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.5.0
    • None
    • cordova-plugin-file
    • Windows Phone

    Description

      When this code is run on Windows Phone:

      // a valid base64-encoded image:
              var imgData = '/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAAHAAgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDkPhh8d/FOp/FTxr8TbCfxDomsWlums6rc6DqktjA9iJo4BaXKx3EN3cpcXs2mxyT/AGs3ABmnk+0SkyKUUVHF3FFbA0MPWhRpTc3VjacOZJUqjpx5U37vuxV0rRbV7Jt3/urgfw0yrPMbjqGKqVYKh7DldOo4N+2oQrS52vjanOXK5Xaj7t2kj//Z',
                  path = 'testImage.jpeg';
      
              var byteArray = base64DecToArr(imgData).buffer;
      
              window.requestFileSystem(
                  LocalFileSystem.PERSISTENT,
                  0,
                  function(fileSystem) {
                      fileSystem.root.getFile(path, { create: true }, function(fileEntry) {
                          fileEntry.createWriter(function(writer) {
                              writer.write(byteArray);
                              writer.onwriteend = function(evt) {
                                  alert('write end');
                              };
                          })
                      });
                  });
      

      where base64DecToArr is a function taken from here: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
      The file that is written is not a valid jpeg file. This issue is caused by deserialization of bytes into `char[]` instead of `byte[]`.

      Attachments

        1. patch.diff
          1 kB
          Kamil Durkiewicz

        Activity

          People

            purplecabbage Jesse MacFadyen
            kdurkiewicz Kamil Durkiewicz
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: