I'm trying to upload a file to AWS using amplify with React js but I'm getting a 07:55.748 AWSS3Provider - error uploading Error: Region is missing.
This is the code that I'm using. I even trying hard coding the region but it still isn't working.
import { v4 as uuid } from 'uuid';
import { withAuthenticator } from '@aws-amplify/ui-react';
import { createDrawing as CreateDrawing } from '../graphql/mutations';
import { listDrawings as ListDrawings } from '../graphql/queries';
import config from '../aws-exports';
const { aws_user_files_s3_bucket: bucket } = config;
export const listDrawings = async () => {
const images = await API.graphql(graphqlOperation(ListDrawings));
console.log(images.data.listDrawings.items);
return images;
};
export const createDrawing = async (file) => {
const region = 'eu-west-1';
const extension = file.name.split('.')[1];
const imgName = file.name.split('.')[0];
if (file) {
const { type: mimeType } = file;
const key = `images/${uuid()}${imgName}.${extension}`;
const url = `https://${bucket}.s3.${region}.amazonaws.com/public/${key}`;
const inputData = { name: imgName, image: url };
try {
await Storage.put(key, file, {
contentType: mimeType
});
await API.graphql(
graphqlOperation(CreateDrawing, { input: inputData })
);
} catch (err) {
console.log('error: ', err);
}
}
};
I also tried updating aws-amplify but it didn't solve my problem once again.