1

I am trying to use p-fileupload in angular for the pdf files, when I select the file, I want to put the pdf image along with the file name. For that, I created the ng-template for the file upload but apparently I am getting the template version as well as the default version of the file upload. How I am remove the default version of the p-fileupload files.

enter image description here

here is the code for my file uploader.

<p-fileUpload
  #uploader
  [multiple]="true"
  [maxFileSize]="1000000"
  [fileLimit]="5"
  dragDropSupport="true"
  [showUploadButton]="false"
  [customUpload]="true"
  (onSelect)="onSelectFile($event, uploader)"
  accept="application/pdf"
>
  <ng-template pTemplate="content">
    <ul *ngIf="uploader.files">
      <li *ngFor="let file of uploader.files">
        <img
          src="/assets/images/pdfimage.png"
        />
        {{ file.name }}
      </li>
    </ul>
  </ng-template>
</p-fileUpload>

1 Answer 1

0

The files of the file upload are avaiable at _files property instead of files. This should show the values.

  <ng-template pTemplate="content">
    <ul *ngIf="uploader.files">
      <li *ngFor="let file of uploader._files"> <!--  changed here! -->
        <img
          src="/assets/images/pdfimage.png"
        />
        {{ file.name }}
      </li>
    </ul>
  </ng-template>

Related Answers with Working Examples:

In the (onRemove) function of a p-fileUpload, is it possible to get a list of the remaining files?

https://stackoverflow.com/questions/79246000/in-the-onremove-function-of-a-p-fileupload-is-it-possible-to-get-a-list-of-th

4
  • The problem is I am getting the template version and the default version of the files. I have made the changes that you suggested, and the result is the same. Commented Dec 9, 2024 at 9:32
  • 1
    @ImranAhmadShahid could you replicate the issue in a stackblitz, you can find sample stackblitz in my linked answers. Commented Dec 9, 2024 at 9:33
  • yes I can try that and will update Commented Dec 9, 2024 at 9:34
  • I have tried there and it seems like it is behaving like my template, stackblitz.com/edit/… In the ng-template we dont have any image but when we select the files it also shows the selected image. template is like this <li *ngFor="let file of uploadedFiles"> {{ file.name }} - {{ file.size }} bytes </li> Commented Dec 9, 2024 at 16:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.