Last active
October 15, 2022 17:14
-
-
Save x8BitRain/ff8b9f23b36f8c0ed8bb7a60f7fea384 to your computer and use it in GitHub Desktop.
PWA Share Target API accept any file type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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