(signedUrl: string, document: Blob)
| 964 | } |
| 965 | |
| 966 | async function uploadDocument(signedUrl: string, document: Blob) { |
| 967 | let mimeType = document.type; |
| 968 | |
| 969 | // Check if the MIME type is supported. |
| 970 | const isSupportedMimeType = |
| 971 | MEMORYSETS.ACCEPTED_MIME_TYPES.includes(mimeType); |
| 972 | |
| 973 | // If not, default to text/plain. |
| 974 | if (!isSupportedMimeType) { |
| 975 | dlog(`Unsupported MIME type ${mimeType}. Defaulting to text/plain`); |
| 976 | mimeType = 'text/plain'; |
| 977 | } |
| 978 | |
| 979 | try { |
| 980 | const response = await fetch(signedUrl, { |
| 981 | method: 'PUT', |
| 982 | headers: { |
| 983 | 'Content-Type': mimeType |
| 984 | }, |
| 985 | body: document |
| 986 | }); |
| 987 | |
| 988 | if (!response.ok) { |
| 989 | const error = await response.text(); |
| 990 | throw new Error( |
| 991 | `HTTP error! status: ${response.status}, message: ${error}` |
| 992 | ); |
| 993 | } |
| 994 | |
| 995 | return response; |
| 996 | } catch (error) { |
| 997 | dlog('Error in uploadDocument:', error); |
| 998 | throw error; |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | export function getMemoryApiUrls({ |
| 1003 | memoryName, |
no test coverage detected