Skip to content

Instantly share code, notes, and snippets.

@ikeyasu
Last active April 17, 2018 15:11
Show Gist options
  • Save ikeyasu/f13c365a005365378ae2453c786c6fb1 to your computer and use it in GitHub Desktop.
Save ikeyasu/f13c365a005365378ae2453c786c6fb1 to your computer and use it in GitHub Desktop.
mturk-upload.html
<p>Please upload your bouncy ball. (<a href="https://en.wikipedia.org/wiki/Bouncy_ball">What is bouncy ball.</a>) You need to take a phone like ...</p>
<ul>
<li>Any size, Any color is okay.</li>
<li>One photo contains <b>two bouncy balls</b>.</li>
<li>Put bouncy ball on flat table, and take a photo from top.</li>
<li>Two bouncy balls needs to be located on random positions. (No need to be on center.)</li>
</ul>
<p>Example<br />
<img src="https://s3.amazonaws.com/ikeyasu-turk/balls/sample_upload.jpg" /></p>
<p>&nbsp;</p>
<p><input id="input_worker_id" name="input_worker_id" type="hidden" /> <script>
$("#input_worker_id").val(turkGetParam('workerId'));
</script></p>
<p><script>
let config = {
region: 'us-east-1',
pool: 'us-east-1:95b3ba5d-be66-40d4-b40f-956ea61861f2',
bucket: 'ikeyasu-mturk-worker-uploads'
}
// Region where your identity pool exists (us-east-1, eu-west-1)
AWS.config.region = config.region;
// Configure the credentials provider to use your identity pool
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: config.pool,
});
let s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: { Bucket: config.bucket }
});
do_upload = () => {
// Reset the status indicator and hidden file uploaded flag
$("#status").text("Uploading...");
$("#file_uploaded").val("false");
s3.createPresignedPost({}, function(err, data) {
if (err) {
alert("There was an upload error. Please contact the Requester.");
} else {
let file = $("#file").prop('files')[0];
let workerId = turkGetParam('workerId');
let assignmentId = turkGetParam('assignmentId');
let hitId = turkGetParam('hitId');
let fileKey = hitId + '-' + assignmentId + '-' + workerId + '-' + file.name;
s3.upload({
Key: fileKey,
Body: file,
ContentType: file.type,
ACL: 'bucket-owner-full-control'
}, function(err, data) {
if (err) {
alert("There was an upload error. Please contact the Requester.");
return false;
}
else{
$("#status").text("Upload successful!");
$("#file_uploaded").val("true");
}
});
}
});
}
$("#upload_file_button").on("click", do_upload);
</script></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment