core/file-picker/file-picker.component.ts
User can upload a binary directly, provide a URL, mark a file as provided by the device, or edit a text file inline.
When editInline is in allowedUploadChoices, project the editor UI
via the [c8yInlineEditor] attribute:
<c8y-file-picker
[allowedUploadChoices]="['uploadBinary', 'uploadUrl', 'editInline']"
[(uploadChoice)]="choice"
[(fileBinary)]="binaryFile"
[(fileUrl)]="fileUrl"
(textFilePicked)="onTextFilePicked($event)"
>
<ng-container c8yInlineEditor>
<input formControlName="editorFilename" />
<c8y-editor formControlName="editorContent"></c8y-editor>
</ng-container>
</c8y-file-picker>
OnInit
OnChanges
| host | { |
| selector | c8y-file-picker |
| standalone | true |
| imports |
FormsModule
PopoverModule
FormGroupComponent
DropAreaComponent
IconDirective
RequiredInputPlaceholderDirective
C8yTranslatePipe
|
| templateUrl | ./file-picker.component.html |
Properties |
Methods |
Inputs |
Outputs |
| allowedUploadChoices |
Type : UploadChoice[]
|
Default value : ['uploadBinary', 'uploadUrl']
|
| config |
Type : FilePickerConfig
|
Default value : { maxlength: 2048 }
|
| editInlineConfirmMessage |
Type : any
|
Default value : gettext(
'The uploaded file appears to be binary. Switching to inline editing will discard it. Do you want to continue?'
)
|
|
Message of the confirmation dialog shown when switching to |
| editInlineConfirmTitle |
Type : any
|
Default value : gettext('Switch to inline editing')
|
|
Title of the confirmation dialog shown when switching to |
| fileBinary |
Type : DroppedFile
|
| filePickerIndex |
Type : number
|
|
Used only when displaying multiple file pickers in the same view. |
| fileUrl |
Type : string
|
| fileUrlPopover |
Type : string
|
|
Additional string to be displayed in a popover. |
| maxAllowedFiles |
Type : any
|
Default value : Infinity
|
| uploadChoice |
Type : UploadChoice
|
Default value : 'uploadBinary'
|
| fileBinaryChange |
Type : EventEmitter
|
|
Two-way binding companion for |
| fileUrlChange |
Type : EventEmitter
|
|
Two-way binding companion for |
| onFilesPicked |
Type : EventEmitter<PickedFiles>
|
| textFilePicked |
Type : EventEmitter
|
|
Fires when a dropped file is detected as text and |
| uploadChoiceChange |
Type : EventEmitter
|
| clearInputFromUrl |
clearInputFromUrl()
|
|
Triggered when user changes upload choice, from upload url to upload binary.
Returns :
void
|
| clearSelectedFiles |
clearSelectedFiles()
|
|
Triggered when user changes upload choice, to avoid cumulation of droppedFiles.
Returns :
void
|
| isPopoverUsed |
isPopoverUsed()
|
|
Checks if there is popover to display.
Returns :
boolean
|
| Async onFileDropped | ||||||
onFileDropped(droppedFiles: DroppedFile[] | null)
|
||||||
|
Triggered by drop-area when a file is dropped (or cleared).
When
Parameters :
Returns :
Promise<void>
|
| onFileUrlChange | ||||||
onFileUrlChange(urlStr: string)
|
||||||
|
Triggered when user puts binary's url to upload.
Parameters :
Returns :
void
|
| setProvidedOption |
setProvidedOption()
|
|
Returns :
void
|
| dropArea |
Type : DropAreaComponent
|
Decorators :
@ViewChild(DropAreaComponent, {static: true})
|
| droppedFiles |
Type : DroppedFile[]
|
| providedPopover |
Type : unknown
|
Default value : gettext(
'Use this option if the device will resolve the binary itself. No file is uploaded.'
)
|
| ValidationPattern |
Type : unknown
|
Default value : ValidationPattern
|
Allows to select a binary for upload, or to specify URI to external resource. Component provides drop area functionality allowing you to just drop files within specified area.
Attributes:
<div>
<c8y-file-picker
[maxAllowedFiles]="1"
(onFilesPicked)="onFile($event)"
[uploadChoice]="uploadChoice"
[fileUrl]="binary.url"
[fileBinary]="binary.file"
[fileUrlPopover]="textForPopover">
</c8y-file-picker>
</div><div class="form-group">
<label
class="c8y-radio"
title="{{ 'Upload a binary' | translate }}"
>
<input
name="uploadChoice-{{ filePickerIndex }}"
type="radio"
value="uploadBinary"
#radio
[(ngModel)]="uploadChoice"
(click)="clearInputFromUrl()"
/>
<span></span>
<span>{{ 'Upload a binary' | translate }}</span>
</label>
<label
class="c8y-radio"
title="{{ 'Provide a file path' | translate }}"
data-cy="file-picker--file-path-input"
>
<input
name="uploadChoice-{{ filePickerIndex }}"
type="radio"
value="uploadUrl"
#radio
[(ngModel)]="uploadChoice"
(click)="clearSelectedFiles()"
/>
<span></span>
<span>
{{ 'Provide a file path' | translate }}
</span>
@if (isPopoverUsed()) {
<button
class="btn-help"
[attr.aria-label]="'Help' | translate"
popover="{{ fileUrlPopover | translate }}"
placement="top"
placement="top"
triggers="focus"
container="body"
type="button"
data-cy="file-picker--file-path-help"
></button>
}
</label>
@if (allowedUploadChoices.includes('provided')) {
<label
class="c8y-radio"
title="{{ 'Mark as provided' | translate }}"
>
<input
name="uploadChoice-{{ filePickerIndex }}"
type="radio"
value="provided"
#radio
[(ngModel)]="uploadChoice"
(click)="setProvidedOption()"
/>
<span></span>
<span>{{ 'Provided' | translate }}</span>
<button
class="btn-help"
[attr.aria-label]="'Help' | translate"
popover="{{ providedPopover | translate }}"
placement="top"
triggers="focus"
container="body"
type="button"
></button>
</label>
}
@if (allowedUploadChoices.includes('editInline')) {
<label
class="c8y-radio"
title="{{ 'Edit inline' | translate }}"
>
<input
name="uploadChoice-{{ filePickerIndex }}"
type="radio"
value="editInline"
#radio
[checked]="uploadChoice === 'editInline'"
(click)="selectEditInline(); $event.preventDefault()"
/>
<span></span>
<span>{{ 'Edit inline' | translate }}</span>
</label>
}
</div>
<div [hidden]="uploadChoice !== 'uploadBinary'">
<c8y-form-group class="m-0">
<c8y-drop-area
class="drop-area-sm"
[title]="'Drop file or click to browse' | translate"
[attr.aria-label]="'Drop file or click to browse' | translate"
(dropped)="onFileDropped($event)"
[maxAllowedFiles]="maxAllowedFiles"
[files]="droppedFiles"
></c8y-drop-area>
</c8y-form-group>
</div>
@if (uploadChoice === 'editInline') {
<div class="d-col flex-grow min-height-0">
<ng-content select="[c8yInlineEditor]"></ng-content>
</div>
}
<div [hidden]="uploadChoice !== 'uploadUrl'">
<c8y-form-group class="m-0">
<div class="m-b-4 p-b-8">
<div class="input-group">
<span class="input-group-addon">
<i c8yIcon="globe"></i>
</span>
<input
class="form-control"
placeholder="{{ 'e.g.' | translate }} http://example.com/binary.zip"
name="fileUrl"
type="text"
required
data-cy="file-picker--fileUrl"
[(ngModel)]="fileUrl"
(ngModelChange)="onFileUrlChange($event)"
maxlength="{{ config.maxlength }}"
[pattern]="ValidationPattern.rules.noWhiteSpaceOnly.pattern"
/>
</div>
</div>
</c8y-form-group>
</div>