Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle complete response #406

Closed
Aviico2 opened this issue Feb 19, 2023 · 2 comments
Closed

How to handle complete response #406

Aviico2 opened this issue Feb 19, 2023 · 2 comments

Comments

@Aviico2
Copy link

Aviico2 commented Feb 19, 2023

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
Copy link
Owner

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
Copy link
Author

Aviico2 commented Feb 19, 2023

Thanks @kukhariev It's working.

@Aviico2 Aviico2 closed this as completed Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants