Skip to content

Instantly share code, notes, and snippets.

@gadtfly
Last active June 17, 2024 20:00
Show Gist options
  • Select an option

  • Save gadtfly/6b316790c31e35446388eece10de4de5 to your computer and use it in GitHub Desktop.

Select an option

Save gadtfly/6b316790c31e35446388eece10de4de5 to your computer and use it in GitHub Desktop.
Quick-and-dirty, relatively simple, media sharing with remote iOS devices via Amazon S3 and VLC
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script>
var bucket = window.location.host.split('.')[0] || parse_querystring(window.location).bucket
var url_for = parse_querystring(window.location).download ? c : vlc_url
document.addEventListener('DOMContentLoaded', function(){
ajax('GET', s3_url(bucket), function(event){
get_filenames(event.target.responseXML).forEach(function(filename){
document.body.appendChild(element('a', {href: url_for(s3_url(bucket, filename))},
text(filename)
))
})
})
})
function c(x){
return x
}
function vlc_url(url){
// Doesn't work on M's iPad for some fucking reason... but works on N's iPhone, with same versions of everything
// 'vlc://s3.amazonaws.com/'+[bucket,filename].join('/')
return 'vlc://'+url
}
function s3_url(bucket, filename){
return 'https://s3.amazonaws.com/'+[bucket,filename].join('/')
}
function get_filenames(bucket_index_xml_document){
return to_array(bucket_index_xml_document.getElementsByTagName('Contents')).filter(function(contents){
return contents.getElementsByTagName('Size')[0].textContent != 0 && contents.getElementsByTagName('Key')[0].textContent != 'index.html'
}).map(function(contents){
return contents.getElementsByTagName('Key')[0].textContent
})
}
function to_array(arraylike){
return Array.prototype.slice.call(arraylike)
}
function parse_querystring(location){
var params = {}
location.search.substring(1).split('&').map(function(s){
return s.split('=')
}).forEach(function(key_value){
params[key_value[0]] = key_value[1]
})
return params
}
function element(tag, attributes, content){
var element = document.createElement(tag)
Object.keys(attributes).forEach(function(attribute){
element.setAttribute(attribute, attributes[attribute])
})
element.appendChild(content)
return element
}
function text(text){
return document.createTextNode(text)
}
function ajax(method, url, success){
var xhr = new XMLHttpRequest()
xhr.open(method, url)
xhr.addEventListener('load', success)
xhr.send()
}
</script>
<style>
body {
background-color: #C7D0D5;
}
a {
display: block;
padding: 10px;
margin: 1px;
border-radius: 5px;
background-color: #93B1C6;
font: 2em -apple-system, BlinkMacSystemFont, helveticaneue, sans-serif;
color: #F5F5F5;
text-decoration: none;
}
a:active {
background-color: #A7A37E;
color: #EFECCA;
}
</style>
</head>
<body>
</body>
</html>

Initial Setup

  1. Save index.html

  2. Create bucket

  3. Properties > Static Website Hosting > Enable website hosting > index.html > Save

  4. Upload > Add Files > index.html

  5. Set Details > Set Permissions > Make everything public > Start Upload

  6. Note endpoint (<your-bucket-name>.s3-website-<your-region>.amazonaws.com)

Uploading

  1. Upload > Add Files > pick your files

  2. Set Details > Set Permissions > Make everything public > Start Upload

Playing on target iOS device

  1. Install VLC from app store

  2. Browse to endpoint (in iOS Safari browser)

  3. Select file to play

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment