![](/img/trans.png)
[英]How to set allowsEditing for UIImagePickerController only for videos selected from photo library in iOS?
[英]File size is 0 only for videos in Ionic on iOS 13.2 when selecting videos from Photo Library
在我的 Ionic3 應用程序中,我正在計算文件大小,如下所示。
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;
}
以上代碼在 iOS 13.2 以下的所有 Android 設備和 iOS 設備上完美運行。
但是在大於 13.2 的 iOS 設備上從照片庫中選擇視頻時, size
為 0 僅適用於視頻文件。
但是從 iCloud Drive 中選擇視頻時效果很好。
非常感謝任何幫助。
在StackBlitz上查找問題。
我一直在努力尋找解決方案超過 7 天。 我將我的發現作為答案發布,因為它將幫助面臨此問題的人。
實際上,我的目的是將帶有其他數據的文件上傳到Rest API
。 這些功能僅在版本為13.2的iOS
設備上失敗。 我找不到解決方案,我決定改變整個實現。 然后我使用相機插件和文件插件從照片庫中獲取 select 視頻。 該實現也僅在版本為13.2的iOS
設備上存在相同的問題。
當使用相機插件在所選視頻文件的文件插件中使用readAsDataURL(path, file)
、 readAsArrayBuffer(path, file)
或readAsBinaryString(path, file)
方法時,它給出了FileError 1
(未找到錯誤)。
問題出在相機插件中。 此錯誤的原因是照片庫資產 url 在 iOS 13 上無效。 為此存在Git 集線器問題。
我在This Link上找到了解決此問題的臨時方法。
我在platforms/ios
中手動編輯了src/ios/CDVCamera.h
和src/ios/CDVCamera.m
,如下。
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;
希望這可以幫助面臨這個問題的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.