1
I have an application problem that when I send files via POST and the image is larger in Mb Cors error occurs, images of a few kb work normally. Dotnet core api In the api I already added Cors and added permissions in configure services:
services.AddCors(options => options.AddPolicy("CorsPolicy", builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
//.AllowCredentials())
));
and no configure:
app.UseCors("CorsPolicy");
Testing via Postman, regardless of image size, no error occurs.
With small image and no error occurs:
With large image and error occurs:
React Code with Axios
api
.post(`anuncio/${anuncio.idImovel}/imagem`, data, {
mode: 'cors',
headers: {
'content-type': 'multipart/form-data',
'Access-Control-Allow-Origin':'*',
authorization: `bearer ${getToken()}`,
},
onUploadProgress: (e) => {
const progress = parseInt(Math.round((e.loaded * 100) / e.total));
this.updateFile(uploadedFile.id, {
progress: progress,
});
},
})
.then((response) => {
this.updateFile(uploadedFile.id, {
uploaded: true,
imagemPrincipal: !principal && index === 0,
id: response.data.id.toString(),
href: response.data.link.href,
});
})
.catch(() => {
this.updateFile(uploadedFile.id, {
error: true,
uploaded: true,
});
});
};
Environmental data Linux server hosted on AWS. We use NGINX on the frontend. Dotnet core (Kestrel on linux). The upload is done to the S3 of aws (I’ve already set the Cors policies in Bucket).
It doesn’t seem q to be a Cors problem. Anyway, you have already activated all exceptions (same handled) in ide?
– tvdias
Another point, n related to the question, but if you don’t do anything with the image (just get it in your api and send it to aws) you can upload it right there. For this you can generate a specific temporary token for a single upload.
– tvdias
Hi @tvdias thanks for the return, your tip is an excellent plan B, it seems that whoever is limiting this is the NGINX, it does not show to be taking the limit setting client_max_body_size XMB. We’ll test it with the Apache to see if it works.
– Bruno Rodrigues
I will activate the exceptions in production, had not done it.
– Bruno Rodrigues