Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230059

Blob.. file.. post

$
0
0

Party it solved the problem:

  pickFile() {
    this.fileChooser.open().then((fileuri) => {
      this.filePath.resolveNativePath(fileuri).then(resolvedNativePath => {
        this.file.resolveLocalFilesystemUrl(resolvedNativePath)
          .then((entry: FileEntry) => {
            (entry).file(file => this.readFile(entry));
          })
          .catch(err => {
          });
      });
    });
  }

  async readFile(file: FileEntry) {
    let contents = null;
    try {
      contents = await Filesystem.readFile({
        path: file.nativeURL,
        // directory: FilesystemDirectory.Documents,
        // encoding: FilesystemEncoding.UTF8
      });

      if (!contents) {
        return;
      }

      return this.post
        .post('Document',
          {
            Document: contents.data,
            DossierId: 4163,
            Libelle: 'rocket star',
            AssistantId: 11
          }, {}).then(result => {
          alert('result');
          alert(JSON.stringify(result));
        })
        .catch(er => {
          alert('er');
          alert(JSON.stringify(er));
        });
    } catch (err) {
      alert('err');
      alert(err);
    }
  }

Unfortunately contents.data seams not to be a valid base64 format, any hints please to convert it to the stream that is required by the api endpoint?


Viewing all articles
Browse latest Browse all 230059

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>