Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
photos.items.map((photo, index) => {
let key = photo.file.key
key = key.substring(key.indexOf('/') + 1) // get rid of folder name in key
Storage.get(key, access)
.then((response) => {
let uri = response.substr(0, response.indexOf('?')) // extract uri from response
if (this.state.allImagesURIs.includes(uri)) {
console.log('KO')
return
} else {
console.log('OK')
this.setState(prevState => ({
allImagesURIs: [...prevState.allImagesURIs, uri]
}))
}
})
.catch(err => console.log(err))
})
}
removeImageFromS3 = async (key) => {
await Storage.remove(key)
.then(result => console.log('Picture deleted', result))
.catch(err => console.log(err))
}
load() {
const { path, textKey, body, contentType, level, track } = this.props;
if (!textKey && !path) {
logger.debug('empty textKey and path');
return ;
}
const that = this;
const key = textKey || path;
logger.debug('loading ' + key + '...');
if (body) {
const type = contentType || 'text/*';
if (!Storage || typeof Storage.put !== 'function') {
throw new Error('No Storage module found, please ensure @aws-amplify/storage is imported');
}
const ret = Storage.put(key, body, {
contentType: type,
level: level? level : 'public',
track
});
ret.then(data => {
logger.debug(data);
that.getText(key, level, track);
})
.catch(err => logger.debug(err));
} else {
that.getText(key, level, track);
}
}
load() {
const { imgKey, path, body, contentType, level, track } = this.props;
if (!imgKey && !path) {
logger.debug('empty imgKey and path');
return ;
}
const that = this;
const key = imgKey || path;
logger.debug('loading ' + key + '...');
if (body) {
const type = contentType || 'binary/octet-stream';
if (!Storage || typeof Storage.put !== 'function') {
throw new Error('No Storage module found, please ensure @aws-amplify/storage is imported');
}
const ret = Storage.put(key, body, {
contentType: type,
level: level? level : 'public',
track
});
ret.then(data => {
logger.debug(data);
that.getImageSource(key, level, track);
})
.catch(err => logger.debug(err));
} else {
that.getImageSource(key, level, track);
}
}
handlePick(data) {
const that = this;
const path = this.props.path || '';
const { textKey, level, fileToKey, track } = this.props;
const { file, name, size, type } = data;
const key = textKey || (path + calcKey(data, fileToKey));
if (!Storage || typeof Storage.put !== 'function') {
throw new Error('No Storage module found, please ensure @aws-amplify/storage is imported');
}
Storage.put(key, file, {
level: level? level: 'public',
contentType: type,
track
})
.then(data => {
logger.debug('handle pick data', data);
that.getText(key, level, track);
})
.catch(err => logger.debug('handle pick error', err));
}
handlePick(data) {
const that = this;
const path = this.props.path || '';
const { imgKey, level, fileToKey, track } = this.props;
const { file, name, size, type } = data;
const key = imgKey || (path + calcKey(data, fileToKey));
if (!Storage || typeof Storage.put !== 'function') {
throw new Error('No Storage module found, please ensure @aws-amplify/storage is imported');
}
Storage.put(key, file, {
level: level? level: 'public',
contentType: type,
track
})
.then(data => {
logger.debug('handle pick data', data);
that.getImageSource(key, level, track);
})
.catch(err => logger.debug('handle pick error', err));
}
handlePick(data) {
const that = this;
const { onPick, onLoad, onError, track, level } = this.props;
if (onPick) { onPick(data); }
const path = this.props.path || '';
const { file, name, size, type } = data;
const key = path + this.getKey(data);
if (!Storage || typeof Storage.put !== 'function') {
throw new Error('No Storage module found, please ensure @aws-amplify/storage is imported');
}
Storage.put(key, file, {
level: level? level: 'public',
contentType: type,
track
})
.then(data => {
logger.debug('handle pick data', data);
const { items } = this.state;
if (items.filter(item => item.key === key).length === 0) {
const list = items.concat(data);
this.marshal(list);
} else {
logger.debug('update an item');
}
if (onLoad) { onLoad(data); }
})
.catch(err => {
getImageSource(key, level, track) {
if (!Storage || typeof Storage.get !== 'function') {
throw new Error('No Storage module found, please ensure @aws-amplify/storage is imported');
}
Storage.get(key, { level: level? level : 'public', track })
.then(url => {
this.setState({
src: url
});
})
.catch(err => logger.debug(err));
}
getText(key, level, track) {
if (!Storage || typeof Storage.get !== 'function') {
throw new Error('No Storage module found, please ensure @aws-amplify/storage is imported');
}
Storage.get(key, { download: true, level: level? level : 'public', track })
.then(data => {
logger.debug(data);
const text = data.Body.toString('utf8');
this.setState({ text });
this.handleOnLoad(text);
})
.catch(err => {
logger.debug(err);
this.handleOnError(err);
});
}
return new Promise((res, rej) => {
if (isStorageSource(source)) {
const storageConfig = {
level: source.level,
identityId: source.identityId,
};
Storage.get(source.key, storageConfig)
.then((url: string) => {
const parser = /https:\/\/([a-zA-Z0-9%-_.]+)\.s3\.[A-Za-z0-9%-._~]+\/([a-zA-Z0-9%-._~/]+)\?/;
const parsedURL = url.match(parser);
if (parsedURL.length < 3) rej('Invalid S3 key was given.');
res({ S3Object: { Bucket: parsedURL[1], Name: parsedURL[2] } });
})
.catch(err => rej(err));
} else if (isFileSource(source)) {
blobToArrayBuffer(source.file)
.then(buffer => {
res({ Bytes: buffer });
})
.catch(err => rej(err));
} else if (isBytesSource(source)) {
const bytes = source.bytes;
if (bytes instanceof Blob) {