flutter_thingsboard_pe_app icon indicating copy to clipboard operation
flutter_thingsboard_pe_app copied to clipboard

photo/image not saved as serverAttribute using mobile action - take photo

Open t0mZ4 opened this issue 5 months ago • 1 comments

Hi trying to use mobile action -> take photo

the camera opens, takes picture, picture is displayed, but not saved as serverAttribute on the device.

using default code

`// Function body to process image obtained as a result of mobile action (take photo, take image from gallery, etc.). 
// - imageUrl - image URL in base64 data format

showImageDialog('Photo', imageUrl);
//saveEntityImageAttribute('image', imageUrl);

function showImageDialog(title, imageUrl) {
    setTimeout(function() {
        widgetContext.customDialog.customDialog(imageDialogTemplate, ImageDialogController, {imageUrl: imageUrl, title: title}).subscribe();
    }, 100);
}

function saveEntityImageAttribute(attributeName, imageUrl) {
    if (entityId) {
        let attributes = [{
            key: attributeName, value: imageUrl
        }];
        widgetContext.attributeService.saveEntityAttributes(entityId, "SERVER_SCOPE", attributes).subscribe(
           function() {
               widgetContext.showSuccessToast('Image attribute saved!');
           },
           function(error) {
               widgetContext.dialogs.alert('Image attribute save failed', JSON.stringify(error));
           }
        );
    }
}

var
  imageDialogTemplate =
    '<div aria-label="Image">' +
    '<form #theForm="ngForm">' +
    '<mat-toolbar fxLayout="row" color="primary">' +
    '<h2>{{title}}</h2>' +
    '<span fxFlex></span>' +
    '<button mat-icon-button (click)="close()">' +
    '<mat-icon>close</mat-icon>' +
    '</button>' +
    '</mat-toolbar>' +
    '<div mat-dialog-content>' +
    '<div class="mat-content mat-padding">' +
    '<div fxLayout="column" fxFlex>' +
    '<div style="padding-top: 20px;">' +
    '<img [src]="imageUrl" style="height: 300px;"/>' +
    '</div>' +
    '</div>' +
    '</div>' +
    '</div>' +
    '<div mat-dialog-actions fxLayout="row">' +
    '<span fxFlex></span>' +
    '<button mat-button (click)="close()" style="margin-right:20px;">Close</button>' +
    '</div>' +
    '</form>' +
    '</div>';

function ImageDialogController(instance) {
  let vm = instance;
  vm.title = vm.data.title;
  vm.imageUrl = vm.data.imageUrl;
  vm.close = function ()
  {
    vm.dialogRef.close(null);
  }
}
`

t0mZ4 avatar Aug 26 '24 12:08 t0mZ4