как получить ответ загрузки s3 от сервиса к компоненту - PullRequest
0 голосов
/ 17 января 2019

У меня есть служба, которая загружает файл на s3 и выдает ответ. Я не могу получить ответ этого метода службы на мой компонент, вызвав его.

Это мой сервис. Я пытаюсь подписать этот метод для получения ответа.

@Injectable()
      export class DBService {
    uploadfile(file,id){

        const bucket = new S3(
          {
            accessKeyId: '*******',
            secretAccessKey: '******',
            region: '****',

          }
        );
        let extn = file.name.split('.').pop();
        let contentType = 'application/octet-stream';
        if (extn == 'html') contentType = "text/html";
        if (extn == 'css') contentType = "text/css";
        if (extn == 'js') contentType = "application/javascript";
        if (extn == 'mp4') contentType = "video/mp4";
        if (extn == 'png' || extn == 'jpg' || extn == 'gif') contentType = "image/" + extn;
        var options = {partSize: 100*1024*1024, queueSize: 1};
        var Obj = this;
        const params = {
          Bucket: 'vod-watchfolder-vidsrc',
          Key: this.IMGFOLDER +id+"/"+ file.name,
          Body: file,
          ContentType:contentType
        };
       bucket.upload(params,options, function (err, data) {
          if (err) {
            alert("Error   " +err);
            console.log('There was an error uploading your file: ', err);
            return false;
          }
         return data;`enter code here`
        })

      }
    }

my Component :

imageUpload(){
  this.myService.uploadfile(this.selectedFile,this.profile.userId).subscribe(
    response =>{
      this.profile.imgPath = response.Location;
      this.imgUrl = response.Location;
      console.log('Successfully uploaded image.', response);
    }
  )
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...