Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete s3 file when delete note #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Delete s3 file when delete note
vfonsecapv committed May 21, 2017
commit 567b4efc5434884c1cbbd89f0e43032807250e15
10 changes: 8 additions & 2 deletions src/containers/Notes.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import {
ControlLabel,
} from 'react-bootstrap';
import LoaderButton from '../components/LoaderButton';
import { invokeApig, s3Upload } from '../libs/awsLib';
import { invokeApig, s3Upload, s3Delete } from '../libs/awsLib';
import config from '../config.js';
import './Notes.css';

@@ -110,7 +110,7 @@ class Notes extends Component {
handleDelete = async (event) => {
event.preventDefault();

const confirmed = window.confirm('Are you sure you want to delete this note?');
const confirmed = confirm('Are you sure you want to delete this note?');

if ( ! confirmed) {
return;
@@ -119,6 +119,12 @@ class Notes extends Component {
this.setState({ isDeleting: true });

try {
if(this.state.note.attachment) {
const s3File = this.state.note.attachment.match(/(?:.*?\/){3}(.*)/);

s3Delete(unescape(s3File[1]), this.props.userToken);
}

await this.deleteNote();
this.props.history.push('/');
}
13 changes: 13 additions & 0 deletions src/libs/awsLib.js
Original file line number Diff line number Diff line change
@@ -58,3 +58,16 @@ export async function s3Upload(file, userToken) {
ACL: 'public-read',
}).promise();
}

export async function s3Delete(filename, userToken) {
await getAwsCredentials(userToken);

const s3 = new AWS.S3();

return s3.deleteObject(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be handled on the server side

{
Bucket: config.s3.BUCKET,
Key: filename
}).promise();

}