39 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import axios from 'axios';
import CONFIG from '@/core/config.js';
const uploadProjectFile = async (projectId, file) => {
try {
const token = localStorage.getItem('access_token');
const formData = new FormData();
formData.append("file", file);
const response = await axios.post(
`${CONFIG.BASE_URL}/project_files/projects/${projectId}/upload`,
formData,
{
headers: {
"Content-Type": "multipart/form-data",
Authorization: `Bearer ${token}`,
},
withCredentials: true,
}
);
return response.data;
} catch (error) {
const errorMessage = error.response?.data?.detail || error.message;
console.error(`Ошибка загрузки файла проекта с ID ${projectId}:`, errorMessage);
if (error.response?.status === 401) {
throw new Error("Недостаточно прав для загрузки файла (401)");
}
if (error.response?.status === 400) {
throw new Error(`Ошибка загрузки: ${errorMessage}`);
}
if (error.response?.status === 404) {
throw new Error("Проект не найден (404)");
}
throw new Error(errorMessage);
}
};
export default uploadProjectFile;