0

Here's a snippet of my code. I'm trying to use a trick I learned which makes use of fetch to convert a file path to a blob. This works fine on my desktop Chrome and on Android, but produces an error on iOS.

import { Capacitor } from '@capacitor/core';
import { VideoEditor } from '@ionic-native/video-editor/ngx';

// irrelevant code here...

return this.videoEditor
  .transcodeVideo(transcodeOptions)
  .then((path) => {
    fullPathTranscoded = "file://" + path
    // I've verified that the error comes from here
    return fetch(Capacitor.convertFileSrc(fullPathTranscoded))
  })
  .then((res) => {
    return res.blob()
  })
  .then(async (blob) => {
    videoInfo = await this.getVideoInfo(fullPathTranscoded)
    return blob
  })

The error is Cross origin requests are only supported for HTTP.

I'm working with Ionic/Angular and building with Capacitor.

There are some similar questions online but I haven't found one that's totally relevant to my setup.

yue you
  • 2,206
  • 1
  • 12
  • 29
Alexander Soare
  • 2,825
  • 3
  • 25
  • 53
  • Why not use [Filesystem](https://capacitor.ionicframework.com/docs/apis/filesystem/#type-434)? – Eldar Nov 29 '19 at 19:34
  • @Eldar I noticed that readFile returns a string, so I'd have to then convert it to a blob/file for my purposes. It felt beautifully simple to use the one liner with fetch, and I remember going around in circles trying other methods provided by Filesystem. If you've got a specific solution though, I'd be happy to hear it. – Alexander Soare Nov 29 '19 at 19:39
  • As `readFile` returns base64 encoded data you can combine your solution with `readFile`. Like [this](https://stackoverflow.com/a/36183085/12354911). – Eldar Nov 29 '19 at 19:50
  • Okay! Will give it a try and get back if there are further issues – Alexander Soare Nov 29 '19 at 20:06
  • @Eldar It worked okay. I had issues on Android, so being in a rush I just checked which platform and used the method that works. Thanks! – Alexander Soare Dec 01 '19 at 10:09

0 Answers0