expo / expo/image-upload-example

Issue Integrating `@aws-sdk/client-s3`

Open
#21 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
263
Forks
92
PR merge metrics
No merged PRs in 30d

Description

I'm trying to use this example to integrate with the AWS S3 SDK. I keep running into this error regardless of the command that I use.

```
TypeError: (0 , import_slurpFile.slurpFile) is not a function
```

Has anyone attempted this thus far? Here is a preview of what my route looks like.

```
import {
PutObjectCommand,
S3Client,
S3ServiceException,
} from '@aws-sdk/client-s3';

const client = new S3Client({
region: 'us-east-1',
credentials: {
accessKeyId: 'random-key',
secretAccessKey: 'random-secret',
},
});

export async function POST(req: Request) {
const formData = await req.formData();

for (const key of formData.keys()) {
if (key.startsWith('photo')) {
const file = formData.get(key);
if (file && typeof file === 'object') {
console.log('file', file.name, file.size);
const buffer = Buffer.from(await file.arrayBuffer());

console.log('buffer', buffer);

const command = new PutObjectCommand({
Bucket: 'development',
Key: `media/${file.name ?? 'photo.png'}`, // Use the file name as the key
Body: buffer,
});

try {
console.log('getting ready to upload');
const response = await client.send(command);
console.log(response);
} catch (caught) {
if (caught instanceof S3ServiceException) {
console.error(
`Error from S3 while uploading object to development. ${caught.name}: ${caught.message}`,
);
} else {
throw caught;
}
}
}
}
}

return Response.json({ success: true });
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.