This project demonstrates an approach to retain access to the native File Web API when using the cordova-file-plugin.
Cordova plugins have the ability to 'clobber' a namespace under window
. In this case, the cordova-plugin-file clobber File
, which is an API provided by the browser. This sample project provides a solution when the user needs access to browsers's File
API, while using the Cordova File Plugin. This is solution is based on a Github comment related to this issue.
To implement in your project:
- In your index.html file, add the follow code as the first child of your body tag:
<script type="text/javascript">window.OriginalFile = window.File;</script>
- This creates a reference called OriginalFile that can be referenced in your Angular code.
- Anywhere you need to use the
OriginalFile
object, you'll need add the following statement (preferrable just below your import statements):
declare var OriginalFile: any;
To instantiate a new File:
const file = new OriginalFile([blob], 'myNewImage.jpg', {type: 'image/jpeg'});
This could be passed into any method that's expecting a web File
object