5

在我的 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 设备上都能完美运行。

但是,在 iOS 设备上从大于 13.2 的照片库中选择视频时,size仅视频文件为 0

但是从 iCloud Drive 中选择视频时效果很好。

非常感谢任何帮助。

在StackBlitz上查找问题。

4

2 回答 2

1

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.

于 2020-01-15T12:12:48.683 回答
1

我认为它不是离子错误。规格说明如下:

获取时,符合要求的用户代理必须返回总字节数

https://w3c.github.io/FileAPI/

好像是ios的bug。

于 2020-01-10T12:36:12.667 回答