如何使用 Slingshot.fileRestrictions 只允许上传 zip 文件?

How to use Slingshot.fileRestrictions to only allow zip files to be uploaded?

我在弹弓源代码中找到了下面的代码

Slingshot.fileRestrictions("myFileUploads", {
  allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
  maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited).
});

他们展示了如何限制图片的上传,我如何只允许上传 .zip 文件?

当发生文​​件上传时,程序包使用 allowedFileTypes 中的内容并为 .zip 文件调用 Slingshot 程序包中名为 Slingshot.Validators.checkFileType to validate the File object's MIME type against (File.type). Based on a list of MIME types 的函数,您希望允许以下操作:

  • application/x-compressed
  • application/x-zip-compressed
  • application/zip
  • multipart/x-zip