Я использую ngx-toastr в своем проекте Angular 5. У меня есть сервис в моем проекте, который используется для загрузки файлов в ведро AWS.
Проблема в том, что я хочу использовать Ngx-toastr внутри моей службы, чтобы уведомить, был ли файл загружен успешно или произошла какая-то ошибка, но он не работает. Кто-нибудь может мне помочь?
Вот мой upload_file_service:
import { Injectable } from '@angular/core';
import * as AWS from 'aws-sdk/global';
import * as S3 from 'aws-sdk/clients/s3';
import { NgxSpinnerService } from 'ngx-spinner';
import { ToastrService } from 'ngx-toastr';
@Injectable()
export class UploadFileService {
FOLDER = 'sample';
constructor(
private spinner: NgxSpinnerService,
private _toastr: ToastrService,
) { }
uploadfile(file) {
this._toastr.info("uploading" , "Info"); //this one is working fine.
// this.spinner.show();
const bucket = new S3(
{
accessKeyId: 'sample',
secretAccessKey: 'sample',
region: 'sample'
}
);
const params = {
Bucket: 'bucek_name',
Key: this.FOLDER + file.name,
Body: file
};
bucket.upload(params, function (err, data) {
if (err) {
console.log('There was an error uploading your file: ', err);
// this.spinner.hide();
// this._toastr.error("File Upload Failed, Please Try Again!", "Error");
return false;
}
console.log('Successfully uploaded file.', data.Location);
localStorage.setItem('uploaded_data_path' , data.Location);
// this._toastr.success("File Upload Faild, Please Try Again!" , "Success");
//not working, gives error that success property is not found.
// this.spinner.hide(); //Not working
return true;
}
);
}
}