I am trying to upload file directly to S3 with pre-signed URL, but can't get it working, checked all the related posts, but can't find any solution. I was able to upload via angular in another project, the below code is working.
const req = new HttpRequest('PUT', preSignedUrl, file, {
reportProgress: true
});
$this._http.request(req).subscribe(e => {
if (e.type === HttpEventType.UploadProgress) {
...
} else if (e instanceof HttpResponse) {
...
}
})
However, now i'm trying to get the same output with Ajax but I'm getting 403 Forbidden. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Here is the code thats not working:
$.ajax({
type: 'PUT',
url: preSignedUrl,
// Content type must much with the parameter you signed your URL with
headers: {
"Content-Type": file.type,
'x-amz-acl': 'public-read'
},
// this flag is important, if not set, it will try to send data as a form
processData: false,
// the actual file is sent raw
data: file
})
.success(function () {
alert('File uploaded');
})
.error(function () {
alert('File NOT uploaded');
console.log(arguments);
});
Please Help