Merge pull request #3133 from dpalou/MOBILE-3780

MOBILE-3780 attachments: Fix detect file size in Android
main
Pau Ferrer Ocaña 2022-02-22 09:39:45 +01:00 committed by GitHub
commit 513e669a12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 46 deletions

View File

@ -0,0 +1,5 @@
:host {
core-loading {
--loading-inline-min-height: 60px;
}
}

View File

@ -42,6 +42,7 @@ import { CoreUtils } from '@services/utils/utils';
@Component({ @Component({
selector: 'core-attachments', selector: 'core-attachments',
templateUrl: 'core-attachments.html', templateUrl: 'core-attachments.html',
styleUrls: ['attachments.scss'],
}) })
export class CoreAttachmentsComponent implements OnInit { export class CoreAttachmentsComponent implements OnInit {
@ -59,16 +60,17 @@ export class CoreAttachmentsComponent implements OnInit {
maxSubmissionsReadable?: string; maxSubmissionsReadable?: string;
unlimitedFiles?: boolean; unlimitedFiles?: boolean;
fileTypes?: CoreFileUploaderTypeList; fileTypes?: CoreFileUploaderTypeList;
loaded = false;
/** /**
* Component being initialized. * @inheritdoc
*/ */
ngOnInit(): void { async ngOnInit(): Promise<void> {
this.files = this.files || []; this.files = this.files || [];
this.maxSize = this.maxSize !== null ? Number(this.maxSize) : NaN; this.maxSize = this.maxSize !== null ? Number(this.maxSize) : NaN;
if (this.maxSize === 0) { if (this.maxSize === 0) {
this.getMaxSizeOfArea(); await this.getMaxSizeOfArea();
} else if (this.maxSize > 0) { } else if (this.maxSize > 0) {
this.maxSizeReadable = CoreTextUtils.bytesToSize(this.maxSize, 2); this.maxSizeReadable = CoreTextUtils.bytesToSize(this.maxSize, 2);
} else if (this.maxSize === -1) { } else if (this.maxSize === -1) {
@ -90,6 +92,8 @@ export class CoreAttachmentsComponent implements OnInit {
if (this.acceptedTypes && this.acceptedTypes != '*') { if (this.acceptedTypes && this.acceptedTypes != '*') {
this.fileTypes = CoreFileUploader.prepareFiletypeList(this.acceptedTypes); this.fileTypes = CoreFileUploader.prepareFiletypeList(this.acceptedTypes);
} }
this.loaded = true;
} }
/** /**

View File

@ -1,37 +1,40 @@
<ion-item class="ion-text-wrap"> <core-loading [hideUntil]="loaded" [fullscreen]="false">
<ion-label> <ion-item class="ion-text-wrap">
<span *ngIf="maxSubmissionsReadable"> <ion-label>
{{ 'core.maxsizeandattachments' | translate:{$a: {size: maxSizeReadable, attachments: maxSubmissionsReadable} } }} <span *ngIf="maxSubmissionsReadable">
</span> {{ 'core.maxsizeandattachments' | translate:{$a: {size: maxSizeReadable, attachments: maxSubmissionsReadable} } }}
<span *ngIf="!maxSubmissionsReadable">{{ 'core.maxfilesize' | translate:{$a: maxSizeReadable} }}</span> </span>
<span [core-mark-required]="required" class="core-mark-required"></span> <span *ngIf="!maxSubmissionsReadable">{{ 'core.maxfilesize' | translate:{$a: maxSizeReadable} }}</span>
</ion-label> <span [core-mark-required]="required" class="core-mark-required"></span>
</ion-item> </ion-label>
<ion-item class="ion-text-wrap" *ngIf="fileTypes && fileTypes.mimetypes && fileTypes.mimetypes.length"> </ion-item>
<ion-label> <ion-item class="ion-text-wrap" *ngIf="fileTypes && fileTypes.mimetypes && fileTypes.mimetypes.length">
<p>{{ 'core.fileuploader.filesofthesetypes' | translate }}</p> <ion-label>
<ul class="list-with-style"> <p>{{ 'core.fileuploader.filesofthesetypes' | translate }}</p>
<li *ngFor="let typeInfo of fileTypes.info"> <ul class="list-with-style">
<strong *ngIf="typeInfo.name">{{typeInfo.name}} </strong>{{typeInfo.extlist}} <li *ngFor="let typeInfo of fileTypes.info">
</li> <strong *ngIf="typeInfo.name">{{typeInfo.name}} </strong>{{typeInfo.extlist}}
</ul> </li>
</ion-label> </ul>
</ion-item> </ion-label>
<div *ngFor="let file of files; let index=index"> </ion-item>
<!-- Files already attached to the submission, either in online or in offline. --> <div *ngFor="let file of files; let index=index">
<core-file *ngIf="!file.name" [file]="file" [component]="component" [componentId]="componentId" [canDelete]="true" <!-- Files already attached to the submission, either in online or in offline. -->
(onDelete)="delete(index, true)" [canDownload]="!file.offline"> <core-file *ngIf="!file.name" [file]="file" [component]="component" [componentId]="componentId" [canDelete]="true"
</core-file> (onDelete)="delete(index, true)" [canDownload]="!file.offline">
</core-file>
<!-- Files added to draft but not attached to submission yet. --> <!-- Files added to draft but not attached to submission yet. -->
<core-local-file *ngIf="file.name" [file]="file" [manage]="true" (onDelete)="delete(index, false)" (onRename)="renamed(index, $event)"> <core-local-file *ngIf="file.name" [file]="file" [manage]="true" (onDelete)="delete(index, false)"
</core-local-file> (onRename)="renamed(index, $event)">
</div> </core-local-file>
</div>
<!-- Button to add more files. --> <!-- Button to add more files. -->
<ion-button expand="block" <ion-button expand="block"
*ngIf="unlimitedFiles || (maxSubmissions !== undefined && maxSubmissions >= 0 && files && files.length < maxSubmissions)" *ngIf="unlimitedFiles || (maxSubmissions !== undefined && maxSubmissions >= 0 && files && files.length < maxSubmissions)"
class="ion-text-wrap ion-margin" (click)="add()"> class="ion-text-wrap ion-margin" (click)="add()">
<ion-icon name="fas-plus" slot="start" aria-hidden="true"></ion-icon> <ion-icon name="fas-plus" slot="start" aria-hidden="true"></ion-icon>
{{ 'core.fileuploader.addfiletext' | translate }} {{ 'core.fileuploader.addfiletext' | translate }}
</ion-button> </ion-button>
</core-loading>

View File

@ -204,16 +204,12 @@ export class CoreFileUploaderHelperProvider {
// Check that size isn't too large. // Check that size isn't too large.
if (maxSize !== undefined && maxSize != -1) { if (maxSize !== undefined && maxSize != -1) {
try { const fileEntry = await CoreFile.getExternalFile(path);
const fileEntry = await CoreFile.getExternalFile(path);
const fileData = await CoreFile.getFileObjectFromFileEntry(fileEntry); const fileData = await CoreFile.getFileObjectFromFileEntry(fileEntry);
if (fileData.size > maxSize) { if (fileData.size > maxSize) {
throw this.createMaxBytesError(maxSize, fileEntry.name); throw this.createMaxBytesError(maxSize, fileEntry.name);
}
} catch (error) {
// Ignore failures.
} }
} }