Skip to content

Instantly share code, notes, and snippets.

@x8BitRain
Last active October 15, 2022 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x8BitRain/ff8b9f23b36f8c0ed8bb7a60f7fea384 to your computer and use it in GitHub Desktop.
Save x8BitRain/ff8b9f23b36f8c0ed8bb7a60f7fea384 to your computer and use it in GitHub Desktop.
PWA Share Target API accept any file type
// using 'application/*' doesn't do the trick but adding as many mimetypes and filetypes as you can seems to get the serviceworker to accept them if they are listed explicitly.
import mimeDb from 'mime-db'
import fileTypes from './src/utils/fileTypes' // from https://github.com/dyne/file-extension-list/blob/master/pub/extensions.json
const allFileTypesAndMimes = () => {
return process.env.NODE_ENV === 'production'
? [...Object.keys(mimeDb), ...fileTypes]
: []
}
const makeManifest = () => {
return manifest {
name: 'name',
short_name: 'name',
theme_color: '#282829',
background_color: '#282829',
start_url: '/',
display: 'standalone',
icons: [...],
share_target: {
action: '/_share',
method: 'POST',
enctype: 'multipart/form-data',
params: {
title: 'title',
text: 'body',
url: 'url',
files: [
{
name: 'text',
accept: ['text/plain', 'text/string'],
},
{
name: 'media',
accept: [
'audio/*',
'image/*',
'video/*',
...allFileTypesAndMimes(),
],
},
],
},
},
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment