mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
fix: update upload handling in uploads.ts for AWS S3 compatibility
- Changed response type from 'stream' to 'arraybuffer' in downloadFromUrl to accommodate different data handling. - Added logic to include 'Content-Length' header for AWS S3 uploads to prevent 501 Transfer-Encoding errors. This update enhances the upload functionality by ensuring compatibility with AWS S3 requirements, improving the reliability of file uploads.
This commit is contained in:
parent
508a5bfb51
commit
c933cc5194
1 changed files with 14 additions and 4 deletions
|
|
@ -109,7 +109,7 @@ export const downloadFromUrl = async (
|
|||
) => {
|
||||
// download the content as stream and max 10MB
|
||||
const response = await axios.get<Buffer>(contentObjUrl, {
|
||||
responseType: 'stream',
|
||||
responseType: 'arraybuffer',
|
||||
maxContentLength,
|
||||
timeout,
|
||||
})
|
||||
|
|
@ -123,11 +123,21 @@ export const uploadToSignedUrl = async (
|
|||
contentType: string,
|
||||
timeout?: number
|
||||
) => {
|
||||
// Check if this is an AWS S3 URL (requires Content-Length header)
|
||||
const isAwsS3 = uploadSignedUrl.includes('amazonaws.com')
|
||||
|
||||
const headers: Record<string, string | number> = {
|
||||
'Content-Type': contentType,
|
||||
}
|
||||
|
||||
// AWS S3 requires Content-Length header to avoid 501 Transfer-Encoding error
|
||||
if (isAwsS3) {
|
||||
headers['Content-Length'] = data.length
|
||||
}
|
||||
|
||||
// upload the stream to the signed url
|
||||
await axios.put(uploadSignedUrl, data, {
|
||||
headers: {
|
||||
'Content-Type': contentType,
|
||||
},
|
||||
headers,
|
||||
maxBodyLength: maxContentLength,
|
||||
timeout,
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue