base_ui/services/fileUploadService.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2025-02-01 09:34:55 +00:00
// // file-upload.service.js
// // import * as axios from 'axios';
// // const BASE_URL = 'http://localhost:3001';
// // function upload(formData) {
// // const url = `${BASE_URL}/photos/upload`;
// // return axios.post(url, formData)
// // // get data
// // .then(x => x.data)
// // // add url field
// // .then(x => x.map(img => Object.assign({},
// // img, { url: `${BASE_URL}/images/${img.id}` })));
// // }
// // file-upload.fake.service.js
// function upload(formData) {
// const photos = formData.getAll('photos');
// const promises = photos.map((x) => getImage(x)
// .then(img => ({
// id: img,
// originalName: x.name,
// fileName: x.name,
// url: img
// })));
// return Promise.all(promises);
// }
// function getImage(file) {
// return new Promise((resolve, reject) => {
// const fReader = new FileReader();
// const img = new Image();
// fReader.onload = (e) => {
// img.src = fReader.result;
// resolve(getBase64Image(img));
// }
// fReader.readAsDataURL(file);
// })
// }
// function getBase64Image(img) {
// const canvas = document.createElement('canvas');
// canvas.width = img.width;
// canvas.height = img.height;
// const ctx = canvas.getContext('2d');
// ctx.drawImage(img, 0, 0);
// const dataURL = canvas.toDataURL('image/png');
// return dataURL;
// }
// export { upload }