简体   繁体   中英

Download files from GUN

trying to download a file that uploads to GUN with this code



 <p>Drag & drop videos, songs, or images! <input type="file" multiple></p>

<button  id="btn" /></button>


<script>
var gun = Gun(location.origin + '/gun');

$('html').upload(function resize(eve, up){
  if(up){ return up.shrink(eve, resize, 1024) }
  var b64 = (eve.base64 || ((eve.event || eve).target || eve).result || eve);
  gun.get('test').get(eve.id).put(b64);
});

gun.get('test').map().on(function(data){
  if(!data){ return }
  var type = data.split(';')[0], ui;
  if(type.indexOf('image') + 1){ ui = $("img").get(0) }
  if(type.indexOf('video') + 1){ ui = $('video').get(0) }
  if(type.indexOf('audio') + 1){ ui = $('audio').get(0) }
  if(!ui){ return }
  $(ui).clone().prependTo('center').get(0).src = data;
})

</script>

if id="btn" could be used to trigger the download how would it be done?

Right-click and "save as".

Or check out this SO:

How to create a file in memory for user to download, but not through server?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM