Add image resizing utility and integrate it into product image upload process
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {forkJoin, map, of, switchMap, Observable, catchError} from 'rxjs';
|
||||
import {forkJoin, map, of, switchMap, Observable, catchError, from} from 'rxjs';
|
||||
import {PsItem} from '../interfaces/ps-item';
|
||||
import {PsProduct} from '../interfaces/ps-product';
|
||||
import {ProductListItem} from '../interfaces/product-list-item';
|
||||
@@ -499,9 +499,20 @@ export class PrestashopService {
|
||||
}
|
||||
|
||||
uploadProductImage(productId: number, file: File) {
|
||||
const fd = new FormData();
|
||||
fd.append('image', file);
|
||||
return this.http.post(`${this.base}/images/products/${productId}`, fd);
|
||||
// 1) Compression AVANT upload
|
||||
return from(resizeImage(file, 1600, 1600, 0.8)).pipe(
|
||||
switchMap(compressedFile => {
|
||||
const fd = new FormData();
|
||||
fd.append('image', compressedFile); // ← image compressée
|
||||
|
||||
// 2) Envoi vers ton backend (identique à avant)
|
||||
return this.http.post(
|
||||
`${this.base}/images/products/${productId}`,
|
||||
fd,
|
||||
{ reportProgress: true, observe: 'events' }
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// -------- Stock (quantité) — gestion fine via stock_availables
|
||||
|
||||
Reference in New Issue
Block a user