Событие Angular при изменении добавляет фотографии в базу данных и сохраняет их в правильная папка, но она не работает на камере мобильного телефона, только на компьютере
Код: Выделить всё
async onFileSelected(event: Event): Promise {
const input = event.target as HTMLInputElement;
if (input.files && input.files[0]) {
const file = input.files[0];
this.selectedFile = file;
const reader = new FileReader();
reader.onload = () => {
this.photoPreview = reader.result as string;
};
reader.readAsDataURL(file);
this.formData = new FormData();
this.formData.append('image', this.selectedFile);
let result = await this.api.addPhoto(this.formData);
}
}
addPhoto(photo) {
return new Promise(async (resolve, reject) => {
try {
await this.http
.post(this.url + 'upload', photo)
.subscribe((data) => {
resolve(data);
});
} catch (err) {
console.log(err);
}
});
}
Код: Выделить всё
app.post('/upload', upload.single('image'), (req, res) => {
if (!req.file) return res.status(400).send('No file uploaded.');
const image = req.file.buffer;
const query = 'INSERT INTO images (photo) VALUES (?)';
db.query(query, [image], (err, result) => {
if (err) {
console.error(err);
return res.status(500).send('Database error.');
}
res.send('Image uploaded successfully.');
});
});
Подробнее здесь: https://stackoverflow.com/questions/793 ... o-database
Мобильная версия