网站搜索

javascript - 在 angular 8 中显示流文件


我创建了一个组件,用于预览文件 音频、视频、图片 等。

但是我在这个上有问题:

它没有显示任何东西。网址是正确的,当我在控制台打印地址文件并复制到浏览器时,它显示文件,但在我的组件中却不显示文件。

    export interface DialogData {
    src: string;
    type: TypeFile;
    apiControllName: string;
}

declare const require: any;

@Component({
    selector: 'kt-preview',
    templateUrl: './preview.component.html',
    styleUrls: ['./preview.component.scss']
})
export class PreviewComponent implements OnInit, OnDestroy {

    @Output() showButton = new EventEmitter<boolean>();

    subscriptions: Subscription;
    thumbnail: any;
    fileSource: any;
    Video = 'Video';
    Picture = 'Picture';
    Text = 'Text';
    Sound = 'Sound';
    type: any;
    isLoading: boolean;
    showVid: any;
    fileType = TypeFile;
    show = true;
    url: string;
    AdressFile: string;

    constructor(
        @Inject(MAT_DIALOG_DATA) public data: DialogData
        , @Inject(APP_CONFIG) private appConfig: IAppConfig
        , private dialogRef: MatDialogRef<PreviewComponent>
        , private authService: AuthService
        , private sanitizer: DomSanitizer) {

    }



    @HostListener('window:keyup.esc') onKeyUp(): void {
        this.dialogRef.close();
    }

    ngOnInit(): void {
        if (this.data.src.startsWith('data:image/png;base64,')) {
            this.AdressFile = this.data.src;
        } else {
            this.AdressFile = this.appConfig.apiEndpoint + '/' + this.data.src + '/?access_token=' + this.authService.getRawAuthToken(AuthTokenType.AccessToken);
        }
        this.type = this.data.type;
        this.AdressFile = this.url;
        this.show = false;
    }

    ngOnDestroy(): void {
        if (this.subscriptions) {
            this.subscriptions.unsubscribe();
        }
    }

    createImageFromBlob(image: Blob): void {
        const blob = new Blob([image], { type: 'application/octet-stream' });
        this.fileSource = this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob));
    }

    close(): void {
        this.dialogRef.close();
    }
}

以及这个 HTML 文件:

    <div class="toolbar col-md-12 col-sm-12 col-lg-12 col-xl-12 p-0">
    <div class="topbar col-md-12 col-xl-12 col-sm-12 col-xl-12 col-lg-12">
        <div class="detail-title">
            <label>نمایش</label>
        </div>
        <span>
            <i (click)="close()" class="fas fa-times"></i>
        </span>
    </div>
</div>
<div class="col-md-12 col-sm-12 col-lg-12 col-xl-12 p-0 prev">
    <!-- Video Show -->
    <div *ngIf="data.type===1">
        <video autoplay controls>
            <source src="{{data.src}}" type="video/mp4">
            <source src="{{data.src}}" type="video/ogg">
            Your browser does not support the video tag.
        </video>
    </div>
    <div *ngIf="type===fileType[1]" id="video_bg">
        <video controls autoplay>
            <source [src]="AdressFile" type="video/mp4">
            <source [src]="AdressFile" type="video/ogg">
            Your browser does not support the video tag.
        </video>
    </div>
    <!-- PDF Show -->
    <div *ngIf="data.type===0">
        <a href="{{data.src}}" target="_blank"></a>
    </div>
    <div *ngIf="type===fileType[0]">
        <a [href]="AdressFile" target="_blank"></a>
    </div>
    <!-- Sound Show -->
    <div *ngIf="data.type===2">
        <audio controls>
            <source src="{{data.src}}" type="audio/ogg">
            <source src="{{data.src}}" type="audio/mpeg">
            Your browser does not support the audio element.
        </audio>
    </div>
    <div *ngIf="type===fileType[2]" id="sound_bg">
        <audio controls autoplay>
            <source [src]="AdressFile" type="audio/mp3">
        </audio>
    </div>
    <!-- Image Show -->
    <div *ngIf="data.type===3">
        <div class="img col-md-12 col-xl-12 col-sm-12 col-xl-12 p-0">
            <img *ngIf="!isLoading" src="{{AdressFile}}" class=" float-left" alt="...">
        </div>
    </div>
    <div *ngIf="type===fileType[3]">
        <div class="img col-md-12 col-xl-12 col-sm-12 col-xl-12 p-0">
            <img *ngIf="!isLoading" [src]="AdressFile" class=" float-left" alt="...">
        </div>
    </div>
</div>

问题出在哪里?我该怎么解决它??