In a new project using Angular 4, you can easily create a simple text File object by following the constructor:
const textfile = new File (['abcd'], 'text.txt')
console.log(textfile)
When looking at the console output in VSCode, the expected result is shown:
File(13) {name: "text.txt", lastModified: 1520684955392, lastModifiedDate: Sat Mar 10 2018 13:29:15 GMT+0100 (Standard romance time…, webkitRelativePath: "", size: 13, …}
lastModified:1520684955392
lastModifiedDate:Sat Mar 10 2018 13:29:15 GMT+0100 {}
name:"text.txt"
size:13
type:"text/plain"
webkitRelativePath:""
__proto__:File {name: <accessor>, lastModified: <accessor>, lastModifiedDate: <accessor>, …}
However, when the same code is executed on a fresh Ionic 3 project, it outputs incorrect properties for the File interface ("name" contains an Array with text content, there is no "name" property, "localURL" holds the file name, and "start," "size," and "end" properties are all 0).
File {name: Array(1), localURL: "text.txt", type: null, lastModified: null, lastModifiedDate: null, …}
end:0
lastModified:null
lastModifiedDate:null
localURL:"text.txt"
name:Array(1) ["text"]
size:0
start:0
type:null
__proto__:Object {slice: , constructor: }
I have tried to simplify my inquiry as much as possible, testing on different devices and verifying Angular and Ionic stable versions. I deployed this project locally in the browser to eliminate any potential device or emulator issues.
I am left wondering if this discrepancy is intentional behavior, a bug within Ionic's Angular implementation, or a misunderstanding of how to utilize this feature.
EDIT:
In response to Reed's comment:
Several suggestions have been made to work around the issue by bypassing Ionic and coding directly in Angular. Unfortunately, at that time, Ionic's documentation and resources did not provide a viable solution.
For me, Ionic seemed to add unnecessary complexity (JS -> TS -> Angular -> cordova/capacitor -> Ionic) onto an already heavy stack.
The solution to my specific problem was to remove Ionic from the equation and streamline the process. This approach may vary depending on individual needs.
For more details, refer to the comments section of this post.