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
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+21 −2
Diff settings

Always

Just for now

@@ -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('/');
}
@@ -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(

This comment has been minimized.

Copy link
@QuantumInformation

QuantumInformation Oct 9, 2017

I think this should be handled on the server side

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

}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.