Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

367
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda