capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

feat(filesystem): support Temp directory

Open bc-m opened this issue 2 years ago • 0 comments

Feature Request

Plugin

Filesystem

Description

On iOS, there is a temporary directory (named "tmp") in the app container. It is not yet possible to access it via the plugin.

Platform(s)

iOS

Preferred Solution

Add directory "TEMP".

Alternatives

As a workaround and to avoid a whole plugin for this task, we currently empty the temporary folder via AppDelegate.swift when the app is started or terminated.

func clearTmp() {
    do {
        let tmpDirURL = FileManager.default.temporaryDirectory
        let tmpDirectory = try FileManager.default.contentsOfDirectory(atPath: tmpDirURL.path)
        try tmpDirectory.forEach { file in
            let fileUrl = tmpDirURL.appendingPathComponent(file)
            try FileManager.default.removeItem(atPath: fileUrl.path)
        }
        print("Clear tmp directory succeed.")
    } catch {
        print("Clear tmp directory failed.")
    }
}

Additional Context

On Capacitor on iOS, when a multi-file selection is made via the HTML file input (<input type="file" multiple />), the selected files are copied to "tmp" within the app container. Unfortunately, the files are not removed automatically in a timely manner. I tried to explain it here: https://github.com/ionic-team/capacitor/issues/5627

Therefore, we need a way to remove them programmatically. I think this plugin is suitable to map this function.

bc-m avatar May 19 '22 16:05 bc-m