Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plupload not working in webview (Android/iOS mobile) #1641

Open
caycewilliams opened this issue Aug 1, 2021 · 0 comments
Open

Plupload not working in webview (Android/iOS mobile) #1641

caycewilliams opened this issue Aug 1, 2021 · 0 comments

Comments

@caycewilliams
Copy link

caycewilliams commented Aug 1, 2021

Hi, whoever comes across this I hope this helps you. Recently I had a problem with plupload where it was not working in a webview. A webview opens when you click on a link in an app and they open the link not in a browser like chrome/safari but in the app.

Versions used: Plupload 2.3.6/Moxie 1.5.7 + DatingScript

The problem was because webview doesn't work with <input type="file" /> when the accept parameter has extensions like "gif,png,jpg". It either needs to be excluded, or have the correct mime types like image/*.

Here is what my plupload javascript with the issue (truncated from php for brevity):

var uploader = new plupload.Uploader({
	        filters : {
	                         mime_types: [
	 				            {title : "Files", extensions : "gif,png,jpg"}
	                         ]
	        }
}

Here is how I fixed the issue,
I removed the mime_types filter (This makes the file input exclude the accept parameter) and added my own _extensions filter to validate the file type.

var uploader = new plupload.Uploader({
	        filters : {
		              _extensions: "gif,png,jpg"
	        }
}
plupload.addFileFilter('_extensions', function(maxSize, file, cb) {
	var fileType = file.type;
	//Make sure file type is valid
	if (!fileType || !fileType.includes('/')) {
		cb(false);
		return;
	}
	//Get extension of file
	var type = fileType.split('/')[1];
	//Get all valid extensions as array
	var exts = 'gif,png,jpg'.split(',');
	//If valid extensions don't include this file type, throw an error
	if (!exts.includes(type)) {
		this.trigger('Error', {
			code: 'EXT_ERROR',
			message: plupload.translate('Not a valid file type: ') + 'gif,png,jpg',
			file: file
		});
		cb(false);
	} else {
		cb(true);
	}
});

I'm not sure how to go about this a better way since the default mime_types filter in plupload doesn't take "image/*". If the maintainer sees this, can you please let me know if this is an acceptable solution, and if there is a patch that can be made for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant