Skip to content

Commit

Permalink
Update s3 uploadImage example (#898)
Browse files Browse the repository at this point in the history
Thanks to @olenderhub for this suggestion
  • Loading branch information
gilest authored Jan 21, 2023
1 parent 53ad98b commit 9f11d75
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions docs/aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,24 @@ import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency';
import fetch from 'fetch';

const parseXml = (rawXml) => {
return new DOMParser().parseFromString(rawXml, 'text/xml');
};

export default class ExampleComponent extends Component {
@task({ maxConcurrency: 3, enqueue: true })
*uploadImage(file) {
const { product } = this.args;

const apiResponse = yield fetch('/api/s3_direct');
const s3Response = yield file.upload(apiResponse.url, {
data: apiResponse.credentials
});
product.url = s3Response.headers.Location;
const apiResponseJson = yield apiResponse.json();

const s3Response = yield file.upload(apiResponseJson.url, {
data: apiResponseJson.credentials,
});
const s3ResponseText = yield s3Response.text();

product.url = parseXml(s3ResponseText).getElementsByTagName('Location')[0].textContent;
yield product.save();
}
}
Expand Down

0 comments on commit 9f11d75

Please sign in to comment.