(relativePath, files)
| 169 | }; |
| 170 | |
| 171 | export const uploadInputFiles = async (relativePath, files) => { |
| 172 | const url = getApiUrl(`/inputs/upload/${encodeURIComponent(relativePath)}`); |
| 173 | const formData = new FormData(); |
| 174 | files.forEach(file => formData.append('files', file, file.name)); // Use 'files' as key |
| 175 | |
| 176 | const response = await fetch(url, { |
| 177 | method: 'POST', |
| 178 | body: formData, |
| 179 | // No 'Content-Type' header, browser sets it with boundary for multipart/form-data |
| 180 | }); |
| 181 | |
| 182 | if (!response.ok && response.status !== 207) { // 207 Multi-Status might indicate partial success |
| 183 | await handleApiError(response, 'upload input files'); |
| 184 | } |
| 185 | // Even on 207, parse the body for details |
| 186 | const result = await response.json(); |
| 187 | if (response.status === 207 && result.errors?.length > 0) { |
| 188 | // Optionally throw a more specific error or handle partial failures |
| 189 | console.warn('Partial upload failure:', result.errors); |
| 190 | // Example: throw new Error(`Upload completed with errors: ${result.errors.join(', ')}`); |
| 191 | } |
| 192 | if (!response.ok && response.status !== 207) { |
| 193 | // Throw if it wasn't OK and wasn't a 207 |
| 194 | throw new Error(result.message || 'Upload failed'); |
| 195 | } |
| 196 | return result; |
| 197 | }; |
| 198 | |
| 199 | export const downloadInputItem = async (relativePath) => { |
| 200 | const url = getApiUrl(`/inputs/download/${encodeURIComponent(relativePath)}`); |
no test coverage detected