In my Ionic3 application I am calculating file size as follows.
HTML
<div>
<input type="file" accept="*" (change)="onSelect($event)">
<button ion-button (click)="calcSize()">calculate size</button>
</div>
<p>Size: {{ size }}</p>
TS
file: File;
size: number;
onSelect(event: any) {
this.file = event.target.files[0];
}
calcSize() {
this.size = this.file.size;
}
Above code is working perfectly on all the Android devices and iOS devices below iOS 13.2.
But when selecting videos from Photo Library on iOS devices with greater than 13.2, the size
is 0 only for video files.
But when selecting videos from iCloud Drive works fine.
Any help is highly appreciated.
Find issue on StackBlitz.
I was struggling more than 7 days finding a solution for this. I am posting my findings as an answer because it will help someone who is facing this issue.
Actually my purpose was uploading file with other data to a Rest API
. Those functionality failed only on iOS
devices with version 13.2. I could not find a solution for that and I decided to change whole implementation. Then I used Camera plugin and File plugin to select videos from the Photo Library. That implementation is also has the same issue only on iOS
devices with version 13.2.
When using readAsDataURL(path, file)
,readAsArrayBuffer(path, file)
or readAsBinaryString(path, file)
methods in File plugin on selected video file using Camera plugin it was giving FileError 1
(not found error).
The issue was in Camera plugin. The reason for this error is photo library asset urls being invalidated on iOS 13. There is a Git Hub Issue for this.
I found a temporary fix for this problem on This Link.
I manually edited src/ios/CDVCamera.h
and src/ios/CDVCamera.m
in platforms/ios
as follows.
CDVCamera.h
@property (strong) CDVCameraPicker* pickerController;
@property (strong) NSMutableDictionary *metadata;
@property (strong) NSDictionary *latestMediaInfo;// Newly added line
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong) NSData* data;
CDVCamera.m
__weak CDVCameraPicker* cameraPicker = (CDVCameraPicker*)picker;
__weak CDVCamera* weakSelf = self;
self.latestMediaInfo = info;// Newly added line
dispatch_block_t invoke = ^(void) {
__block CDVPluginResult* result = nil;
Hope this helps someone facing this issue.