Here's how I personally did it.
I had an api that I can name that returns me basic information:
{ "token":"cfc2b831-...", "url":"https://test-26.s3-eu-west-1.amazonaws.com/", "formData":[ {"bucket":"test-26"}, {"key":"upload/images/11a59aa4..."}, {"Content-Type":"image/"}, {"X-Amz-Algorithm":"AWS4-HMAC-SHA256"}, {"X-Amz-Credential":"AKKWEN2A/20171129/eu-west-1/s3/aws4_request"}, {"X-Amz-Date":"20171129T091121Z"}, {"policy":"eyJleH..."}, {"X-Amz-Signature":"3afbb6d..."} ]}
Then this is my function to send the file to fileDrop:
onFileDrop(fileArr) { const file = fileArr[0]; this.http.post('api/image', {imageType: 'Photo'}).subscribe((r: any) => { const xhr: XMLHttpRequest = new XMLHttpRequest(); const formData = new FormData(); const url = r.url; r.formData.forEach(ent => { Object.entries(ent).forEach(([k, v]) => { formData.append(k, v); }); }); formData.append('file', file); xhr.open('POST', url, true); xhr.send(formData); }); }
source share