Мне нужно передать параметр для разрешения новых Обещаний. Данные, которые мне нужно передать, взяты из ответа axios, вот мой код axios
async function uploadFile() {
const {value: file} = await Swal({
title: 'Select image',
input: 'file',
inputAttributes: {
'accept': 'image/*',
'aria-label': 'Upload your profile picture'
}
})
if (file) {
const reader = new FileReader
reader.onload = (e) => {
Swal({
title: 'Your uploaded picture, Do you want to upload it?',
text: "Ypur photo will be uploaded!",
type: 'info',
imageUrl: e.target.result,
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if(result.value) {
console.log(file, 'file')
let formData = new FormData;
formData.append('photo', file);
let settings = { headers: { 'Content-Type': 'multipart/form-data'}}
axios.post('/agent_dashboard/save_photo', formData)
.then((res) => {
const vl = res.directory => this i want to use
return vl
})
.catch((err) => {
console.log(err.toString(), 'error')
})
}
})
}
reader.readAsDataURL(file)
}
}
Вот моя другая функция, для которой требуется объект ответа axios
ngjs.on('browse', () => {
return new Promise((resolve, reject) => {
try {
const value = uploadFile()
resolve(value)
} catch(e) {
reject(new Error('something failed'))
}
})
})
Когда я запускаю это, все, что у меня есть в консоли, это
Promise {<pending>}
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: undefined
Есть идеи?