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

When I send a file single file use sample code, ,i got a page reload #2146

Open
kdhly opened this issue Jun 5, 2021 · 3 comments
Open

When I send a file single file use sample code, ,i got a page reload #2146

kdhly opened this issue Jun 5, 2021 · 3 comments

Comments

@kdhly
Copy link

kdhly commented Jun 5, 2021

When I send a file single file use sample code,i got a page reload,,
I want to stay on the current page what should I do?
thank you.

@mahendralife
Copy link

mahendralife commented Jun 5, 2021

can you share your code?

@kdhly
Copy link
Author

kdhly commented Jun 6, 2021

onClick(e) {
const fileUpload = this.fileUpload.nativeElement;
fileUpload.onchange = (e) => {
for (let index = 0; index < fileUpload.files.length; index++)
{
const file = fileUpload.files[index];
this.files.push({ data: file, inProgress: false, progress: 0});
}
this.uploadFiles();
};
fileUpload.click();
}

private uploadFiles() {
this.fileUpload.nativeElement.value = '';
this.files.forEach(file => {
this.uploadFile(file);
});
}

uploadFile(file) {
const formData = new FormData();
formData.append('file', file.data);
formData.append('url', "http://localhost:4200/api/upload");
Upload.http({
url: 'http://localhost:4200/api/upload',
data: file
})

html:
<input type="file" #fileUpload id="fileUpload" name="fileUpload" multiple="multiple" accept="image/*" style="display:none;" />

result:
The file was uploaded, but the page was reload.

thank you!

@kdhly
Copy link
Author

kdhly commented Jun 25, 2021

thank you.

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