kukhariev / ngx-uploadx

Angular Resumable Upload Module
https://github.com/kukhariev/ngx-uploadx
MIT License
43 stars 23 forks source link

How to handle complete response #406

Closed Aviico2 closed 1 year ago

Aviico2 commented 1 year ago

Ngx-upload Code:

uploads: Observable<Uploader[]>; options: UploadxOptions = { endpoint: 'http://localhost:4000/uploads', chunkSize: 1024 1024 5, metadata: { foldername: 'hello', }, autoUpload: false, };

constructor(public uploadService: UploadxService) { this.uploads = this.uploadService.connect(this.options); }

pause(): void { this.uploadService.control({ action: 'pause' }); }

upload(): void { this.uploadService.control({ action: 'upload' }); }

node-uploadx Code

const storage = new S3Storage({ endpoint: '', bucket: '', region: 'ap-south-1', apiVersion: '2006-03-01', credentials: { accessKeyId: '', secretAccessKey: '', }, forcePathStyle: true, expiration: { maxAge: '1h', purgeInterval: '15min' }, onComplete: file => { console.log('File upload complete: ', file) return file }, filename: (file) => file.metadata.foldername + '/' + file.originalName });

app.use('/uploads', uploadx({ storage }), function (req, res) { var file = req.body; console.log('File upload complete: ', file.originalName); res.send(file) });

How to handle response when the file is uploaded. Also with the multi-file upload.

kukhariev commented 1 year ago

for example add to constructor

    this.uploads.subscribe(r => {
      const completed = r.filter(u => u.status === 'complete');
      console.log(completed); //  completed uploads array
    });

or

    this.uploadService.events.subscribe(r => {
      if (r.status === 'complete') {
        console.log(r); // completed upload
      }
    });
Aviico2 commented 1 year ago

Thanks @kukhariev It's working.