Return correct file
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
parent
2dd10f04a3
commit
b000d5119a
@ -59,15 +59,13 @@ export class EditImageModalComponent implements OnInit {
|
|||||||
|
|
||||||
save() {
|
save() {
|
||||||
if(this.croppedImage) {
|
if(this.croppedImage) {
|
||||||
|
var blob = this.imageService.dataUrltoBlob(this.croppedImage);
|
||||||
if(this.saveImage) {
|
if(this.saveImage) {
|
||||||
var body = this.croppedImage.substr(23);
|
this.imageService.putImage(this.endpointUrl,blob).subscribe(() => {
|
||||||
this.imageService.putImage(this.endpointUrl,this.imageService.b64toBlob(body,"image/jpeg")).subscribe(() => {
|
|
||||||
this.changed.emit({});
|
this.changed.emit({});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var selectedImage = (this.imageChangedEvent.target.files && this.imageChangedEvent.target.files[0]) ?
|
this.changed.emit({ "croppedImage": this.imageService.blobToFile(blob,"croppedimage.jpg")} );
|
||||||
this.imageChangedEvent.target.files[0] : null;
|
|
||||||
this.changed.emit({ "croppedImage": this.croppedImage, "selectedImage": selectedImage } );
|
|
||||||
}
|
}
|
||||||
this.modalService.dismissAll("Save");
|
this.modalService.dismissAll("Save");
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,12 @@ export class ImageService {
|
|||||||
return this.httpClient.put<any>(endpoint,formData);
|
return this.httpClient.put<any>(endpoint,formData);
|
||||||
}
|
}
|
||||||
|
|
||||||
b64toBlob(b64Data:string, contentType?:string):Blob {
|
dataUrltoBlob(dataURI:string):Blob {
|
||||||
|
var mime = dataURI.split( ';base64,')[0].split(':')[1];
|
||||||
|
var byteCharacters = atob(dataURI.split( ';base64,')[1]);
|
||||||
|
|
||||||
|
|
||||||
const sliceSize = 512;
|
const sliceSize = 512;
|
||||||
const byteCharacters = atob(b64Data);
|
|
||||||
const byteArrays = [];
|
const byteArrays = [];
|
||||||
|
|
||||||
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
||||||
@ -38,7 +41,11 @@ export class ImageService {
|
|||||||
byteArrays.push(byteArray);
|
byteArrays.push(byteArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
const blob = new Blob(byteArrays, {type: contentType});
|
const blob = new Blob(byteArrays, {type: mime});
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blobToFile(blob:Blob, filename:string):File {
|
||||||
|
return new File([blob],filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user