I am trying to upload a shapefile from my frontend to the temporary bucket provided by mapbox like so:
async function upload() {
const credentials = await getCredentials(USERNAME, SECRET_KEY); // gets temporary mapbox credentials
const s3Client = new S3Client({
region: 'us-east-1',
credentials: {
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
sessionToken: credentials.sessionToken
},
requestHandler: new XhrHttpHandler({})
});
const file = document.querySelector('input[type="file"]').files;
try {
const data = await s3Client.send(new PutObjectCommand({
Bucket: credentials.bucket,
Key: credentials.key,
Body: file[0]
}))
console.log(data);
} catch(e) {
console.log(e);
}
}
I keep getting the following CORS error:
Access to XMLHttpRequest at 'https://tilestream-tilesets-production.s3.us-east-1.amazonaws.com/12/_pending/BUCKET/USERNAME?x-id=PutObject' from origin 'https://localhost:1234' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I don't have any control over the AWS account to modify CORS settings, so I'm not really sure what to do here. Everything online says that I need to modify my bucket settings, however this is not possible.