mirror of
https://github.com/amark/gun.git
synced 2025-06-10 08:06:47 +00:00
Create upload.html
This commit is contained in:
parent
d56e06fec7
commit
c45950a771
32
examples/basic/upload.html
Normal file
32
examples/basic/upload.html
Normal file
@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<center>
|
||||
<video width="100%" controls="controls"></video>
|
||||
<img style="max-width: 100%;">
|
||||
<span id="up">Drag & drop video or image to upload!</span>
|
||||
</center>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/lib/upload.js"></script>
|
||||
|
||||
<script>
|
||||
var gun = Gun(location.origin + '/gun');
|
||||
|
||||
$('html').upload(function resize(eve, up){
|
||||
if(up && ((eve.file||{}).type||'').indexOf('image') + 1){
|
||||
return up.shrink(eve, resize, 1024);
|
||||
}
|
||||
var b64 = (eve.base64 || ((eve.event || eve).target || eve).result || eve);
|
||||
gun.get('test').get('paste').put(b64);
|
||||
})
|
||||
|
||||
gun.get('test').get('paste').on(function(data){
|
||||
$('video, img').css({display: 'none'})
|
||||
if(!data){ return }
|
||||
var type = data.split(';')[0], ui;
|
||||
if(type.indexOf('image') + 1){ ui = $("img") }
|
||||
if(type.indexOf('video') + 1){ ui = $('video') }
|
||||
($(ui).css({display: 'block'}).get(0)||{}).src = data;
|
||||
})
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user