You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting an error that says, "[Error: TypeError: stream.arrayBuffer is not a function (it is undefined)] " although the files are uploaded to the bucket
Regression Issue
Select this option if this issue appears to be a regression.
SDK version number
@aws-sdk/client-s3@^3.712.0, .^3.701.0
Which JavaScript Runtime is this issue in?
React Native
Details of the browser/Node.js/ReactNative version
0.76.2
Reproduction Steps
export const uploadFileToR2 = async (file: any) => {
try {
// move these to cloud or backend or cloud functions
const s3Client = new S3Client({
region: 'auto',
endpoint: `https://${config.CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
credentials: {
accessKeyId: config.CLOUDFLARE_ACCESS_KEY,
secretAccessKey: config.CLOUDFLARE_SECRET_KEY
}
})
const { uri, mimeType } = file
// get file from uri
const uriResponse = await fetch(uri)
const contentBody = await uriResponse.blob()
// get file extension
const extension = mime.getExtension(mimeType)
// create random file name
const fileName = `${Date.now()}-${Math.random()
.toString()
.replace('.', '-')}.${extension}`
const putObjectCommand = new PutObjectCommand({
Bucket: config.CLOUDFLARE_BUCKET_NAME,
Key: fileName,
Body: contentBody,
ContentType: mimeType
})
const response = await s3Client.send(putObjectCommand)
return response
} catch (error: any) {
console.log(error?.$response)
throw new Error(error)
}
}
Observed Behavior
(NOBRIDGE) LOG [Error: TypeError: stream.arrayBuffer is not a function (it is undefined)
Expected Behavior
The expected behavior shouldn't throw an error on the catch since the files were uploaded the to bucket successfully
Possible Solution
No response
Additional Information/Context
The tricky part is, the files are uploaded to the bucket. I'm using Cloudflare R2. I even tried older version of the package, still, the error persists. I even tried using axios for getting the blob, still, the error persists.
The text was updated successfully, but these errors were encountered:
This error occurs because SDK expects the Body param of the PutObject to be a readable stream or a typed array like Uint8Array. However, you're passing a Blob object directly, which doesn't have an arrayBuffer method.
You need to convert the Blob to a Uint8Array or a readable stream before passing it to the PutObjectCommand. Here's modified code:
....// create random file nameconstfileName=`${Date.now()}-${Math.random().toString().replace('.','-')}.${extension}`// Convert Blob to Uint8ArrayconstarrayBuffer=awaitcontentBody.arrayBuffer()constbuffer=newUint8Array(arrayBuffer)constputObjectCommand=newPutObjectCommand({Bucket: config.CLOUDFLARE_BUCKET_NAME,Key: fileName,Body: buffer,// Pass the Uint8Array as the BodyContentType: mimeType})....
aBurmeseDev
added
response-requested
Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
p2
This is a standard priority issue
and removed
needs-triage
This issue or PR still needs to be triaged.
labels
Dec 18, 2024
Checkboxes for prior research
Describe the bug
I'm getting an error that says, "[Error: TypeError: stream.arrayBuffer is not a function (it is undefined)] " although the files are uploaded to the bucket
Regression Issue
SDK version number
@aws-sdk/client-s3@^3.712.0, .^3.701.0
Which JavaScript Runtime is this issue in?
React Native
Details of the browser/Node.js/ReactNative version
0.76.2
Reproduction Steps
Observed Behavior
Expected Behavior
The expected behavior shouldn't throw an error on the catch since the files were uploaded the to bucket successfully
Possible Solution
No response
Additional Information/Context
The tricky part is, the files are uploaded to the bucket. I'm using Cloudflare R2. I even tried older version of the package, still, the error persists. I even tried using axios for getting the blob, still, the error persists.
The text was updated successfully, but these errors were encountered: