简体   繁体   English

从 GUN 下载文件

[英]Download files from GUN

trying to download a file that uploads to GUN with this code尝试使用此代码下载上传到 GUN 的文件



 <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?如果 id="btn" 可以用于触发下载,它会如何完成?

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? 如何在 memory 中创建一个文件供用户下载,而不是通过服务器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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