Skip to content

Instantly share code, notes, and snippets.

@marcel-ploch
Created May 10, 2019 09:41
Show Gist options
  • Save marcel-ploch/008288a76e826143d3f91f7222c36e1e to your computer and use it in GitHub Desktop.
Save marcel-ploch/008288a76e826143d3f91f7222c36e1e to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
uploadedImage: String = null;
uploadedModifiedImage: String = null;
constructor(private http: HttpClient) {
}
fileContent: string = '';
file: File = null;
public onChange(fileList: FileList): void {
this.file = fileList[0];
let fileReader: FileReader = new FileReader();
fileReader.onloadend = (x) => {
this.fileContent = fileReader.result;
this.http.post('<<your-lamdba-endpoint>>', {'imageName':this.file.name, 'image':this.fileContent}).subscribe((response) => {
console.log(response);
this.uploadedModifiedImage = response['modifiedUrl'];
this.uploadedImage = response['origUrl'];
})
}
fileReader.readAsDataURL(this.file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment