Skip to content

monoxacc/angular2-multipartForm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular2-multipartForm

A project for Angular 2 apps to upload multipart/form-data.

It is something similar to the ng2-file-upload which only upload file.

How to start

git clone https://github.com/wangzilong/angular2-multipartForm.git
cd angular2-multipartForm
npm install
# run
npm start

Input File in Angularjs 2

home.html

<input type="file" (change)="selectFile($event)">

home.ts

selectFile($event): void {
		var inputValue = $event.target;
		this.file = inputValue.files[0];
		console.debug("Input File name: " + this.file.name + " type:" + this.file.size + " size:" + this.file.size);
	}

Upload multipart/form-data

home.ts

this.upload = () => {
			if (null == this.file || null == this.email || null == this.password){
				console.error("home.ts & upload() form invalid.");
				return;
			}
			// init form item
			if (this.multipartItem == null){
				this.multipartItem = new MultipartItem(this.uploader);
			}
			if (this.multipartItem.formData == null)
				this.multipartItem.formData = new FormData();

      			// fill field of form into formData.
			this.multipartItem.formData.append("email",  this.email);
			this.multipartItem.formData.append("password",  this.password);
			this.multipartItem.formData.append("file",  this.file);
      
      			// set callback function
			this.multipartItem.callback = this.uploadCallback;
			
			// upload
			this.multipartItem.upload();
		}

About

Upload multipart/form-data to remote server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 83.0%
  • HTML 17.0%