for writing Blobs to the filesystem.
javascript
import {Directory} from "@capacitor/filesystem";
import {Capacitor} from "@capacitor/core";
import write_blob from "capacitor-blob-writer";// Firstly, get a reference to a Blob. This could be a file downloaded from the
// internet, or some binary data generated by your app.
let my_video_blob = ...;
// Secondly, write the Blob to disk. The 'write_blob' function takes an options
// object and returns a Promise, which resolves once the file has been
// successfully written.
write_blob({
// The 'path' option should be a string describing where to write the file. It
// may be specified as an absolute URL (beginning with "file://") or a relative
// path, in which case it is assumed to be relative to the 'directory' option.
path: "media/videos/funny.mp4",
// The 'directory' option is used to resolve 'path' to a location on the disk.
// It is ignored if the 'path' option begins with "file://".
directory: Directory.Data,
// The 'blob' option must be a Blob, which will be written to the file. The file
// on disk is overwritten, not appended to.
blob: my_video_blob,
// Fast mode vastly improves read and write speeds on the web platform. For
// files written with 'fast_mode' set to true, Filesystem.readFile will produce
// a Blob rather than a Base64-encoded string. The 'fast_mode' option is
// ignored on iOS and Android. For backwards compatibility, it defaults to
// false.
fast_mode: true,
// If the 'recursive' option is 'true', intermediate directories will be created
// as required. It defaults to 'false' if not specified.
recursive: true,
// If 'write_blob' falls back to its alternative strategy on failure, the
// 'on_fallback' function will be called with the underlying error. This can be
// useful to diagnose slow writes. It is optional.
// See the "Fallback mode" section below for a detailed explanation.
on_fallback(error) {
console.error(error);
}
}).then(function () {
console.log("Video written.");
});