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

Upload Photos #4

Open
djfurman opened this issue Sep 29, 2017 · 4 comments
Open

Upload Photos #4

djfurman opened this issue Sep 29, 2017 · 4 comments
Assignees

Comments

@djfurman
Copy link
Member

Given a random user
AND a photo of that user
When they upload the photos
Then the photos should be stored in S3
AND named with UUIDS

@djfurman
Copy link
Member Author

Generate or get UUIDS in NG or from API Gateway

@djfurman
Copy link
Member Author

Handle for jpg png, etc

@djfurman
Copy link
Member Author

@softEngJason Let me know if you need UUIDs from me

@djfurman
Copy link
Member Author

djfurman commented Oct 1, 2017

/s3-policy-document endpoint created

Submit a GET request to this endpoint to get a one-time use response from the API gateway to securely upload a file into the bucket, includeing a query string for the filename as whatever filename you want to use.

The API gateway will respond with this payload

{
	"signature": "not_displaying_for_safety",
	"encoded_policy": "not_displaying_for_safety",
	"access_key": "not_displaying_for_safety",
	"upload_url": "not_displaying_for_safety",
	"key": "not_displaying_for_safety/[query-string-filename]"
}

When you are ready to upload, include these elements as form data. CORS has already been configured. The following example is BSD-2 licensed showing how to do it with jQuery (sorry I couldn't find something better)

var fd = new FormData();
        fd.append('key', data.key)
        fd.append('acl', 'private');
        fd.append('Content-Type', file.type);
        fd.append('AWSAccessKeyId', data.access_key);
        fd.append('policy', data.encoded_policy)
        fd.append('signature', data.signature);
        fd.append('file', file, file.name);

        $.ajax({
            url: data.upload_url,
            type: 'POST',
            data: fd,
            processData: false,
            contentType: false,
            xhr: this.progress,
            beforeSend: function (req) {
                req.setRequestHeader('Authorization', '');
            }
        }).done(function (response) {
            that.uiElements.uploadButtonContainer.show();
            that.uiElements.uploadProgressBar.hide();
            alert('Uploaded Finished');
        }).fail(function (response) {
            that.uiElements.uploadButtonContainer.show();
            that.uiElements.uploadProgressBar.hide();
            alert('Failed to upload');
        })
    },

Post back an array of the keys when you're ready for me to upload them for facial recognition with the filenames appended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants