【问题标题】:Is it possible to share multiple files with Web Share Target API?是否可以使用 Web Share Target API 共享多个文件?
【发布时间】:2020-05-18 13:29:19
【问题描述】:

是否可以使用Web Share Target API共享多个文件?
我可以在 Google 照片中选择多张图片,点击 Share,然后选择我的 PWA。但只有一个选定的文件被发送到 manifest.json 中给出的share_target URL。
这很奇怪。我错过了什么吗?
谢谢! ????

【问题讨论】:

    标签: javascript android google-chrome progressive-web-apps web-share


    【解决方案1】:

    是的,是的。

    在你的 Web App Manifest 中,使用 like this:

    "share_target": {
      "action": "/_share-target",
      "enctype": "multipart/form-data",
      "method": "POST",
      "params": {
        "files": [{
          "name": "media",
          "accept": ["image/*"]
        }]
      }
    }
    

    在处理传入的POST 对/_share-target/ 请求的服务工作者中,执行like this 的操作:

    const formData = await event.request.formData();
    const mediaFiles = formData.getAll('media');
    
    for (const mediaFile of mediaFiles) {
      // Do something with each mediaFile
    }
    

    在https://scrapbook-pwa.web.app/ 有一个“正在运行”的代码的部署示例

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-03
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    相关资源
    最近更新 更多