Uploading

UniWebView supports uploading files from the disk of your device or from a cloud service to your website.

To show a upload field, use the standard input tag with proper type:

<input type="file" name="filename" accept="image/*">

When the user clicks the select file button, UniWebView will prompt the user from where they want to choose a file. If you specified the "accept" to image/* as the sample above, only photo sources and image files will be available. You can also change the "accept" type to a wider */*, which will cause all types of files be choosable.

NOTICE

Additional steps are required for allowing uploading in some cases, please keep reading below to know more about it.

Additional setup on iOS

On iOS, if you just want let your user upload images from the photo library, it should already work without any effort. However, if you want to let users upload images from cameras, you need to set NSCameraUsageDescription in your Info.plist file in the exported Xcode project, otherwise, your app would crash when users choose to take photo or video by camera.

Additional setup on Android

  1. Please make sure you have added UniWebViewFileChooserActivity into your "AndroidManifest.xml" file. You should have already done that if you followed the Installation Guide when you import UniWebView into your project. Otherwise, please refer to that guide and modify the manifest file.

NOTICE

You don't need the step above if you are using UniWebView 3.7.0 or later, since UniWebView will contain the activity declaration itself. However, you still need to add the turn on write permission as described below.

  1. File uploading on Android needs to create a temporary file on disk so UniWebView needs the external storage writing permission for that. You could set the "Write Permission" to "External (SD Card)" in Android Player Settings → Other Settings → Configuration in Unity.

Now you should be able to choose an image from either camera or photo library, then upload it to your server.