Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
Cannot rename file with ngx-awesome-uploader

I'm using https://www.npmjs.com/package/@sleiss/ngx-awesome-uploader and I cannot find a way to rename the file before uploading.

I've checked the methods, and there seems to be none.

I can rename the file in the adapter, and it uploads with the new name, but on the file list it's still with the old name. So when I try to delete it, it looks for the file with the old name.

Is there a way to rename the file and make it available to the list of files?

Thank you!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think I got it. Given this adapter...

import { AngularFireStorage } from "@angular/fire/storage";
import { FilePickerAdapter, FilePreviewModel, UploadResponse, UploadStatus } from "ngx-awesome-uploader";
import { from, Observable, of } from "rxjs";
import { catchError, map } from "rxjs/operators";
import { Uuid } from "../externalLibraries/uuid/uuid";

export class FirebaseStorageFilePickerAdapter extends FilePickerAdapter {
    constructor(
        private firebaseStorage: AngularFireStorage
    ) {
        super();
    }

    uploadFile(fileItem: FilePreviewModel): Observable<UploadResponse> {
        const file = fileItem.file;
        const path = `public/${Uuid.generateUUID()}.${fileItem.fileName.split('.')[1]}`;
        const ref = this.firebaseStorage.ref(path);
        return from(this.firebaseStorage.upload(path, file, {
            contentType: fileItem.file.type
        })).pipe(
            map((response) => {
                let returnedResponse: UploadResponse;
                switch (response.state.toLowerCase()) {
                    case 'canceled':
                    case 'error':
                    case 'paused':
                        returnedResponse = {
                            status: UploadStatus.ERROR,
                        };
                        break;

                    case 'success':
                        returnedResponse = {
                            status: UploadStatus.UPLOADED,
                            body: response.metadata,
                            progress: 100
                        }
                        break;

                    default:
                        returnedResponse = {
                            status: UploadStatus.IN_PROGRESS,
                            body: response.metadata,
                            progress: (response.bytesTransferred / response.totalBytes) * 100
                        }
                        break;
                }
                return returnedResponse;
            }),
            catchError((err, caught) => {
                console.error(err)
                return of({ status: UploadStatus.ERROR })
            })
        );
    }

    removeFile(fileItem: FilePreviewModel): Observable<any> {
        return this.firebaseStorage.ref(fileItem.uploadResponse.fullPath).delete();
    }
}

My problem was to use public/${fileItem.filename} when trying to delete the file and it didn't exist. However, the new name comes in the uploadResponse object so now I get the fullPath from fileItem.uploadResponse.fullPath

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!