breautek commented on issue #527:
URL:
https://github.com/apache/cordova-plugin-file/issues/527#issuecomment-1357037938
The following code works for me assuming that my app has ownership of the
file (e.g. the file wasn't written by another app)
```javascript
document.addEventListener('deviceready', onDeviceReady, false);
var testFiles = async function() {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory +
'Download', (downloadsDirEntry) => {
console.log('DOWNLOADS', downloadsDirEntry);
downloadsDirEntry.getFile('test1.txt', { create: true }, (fileEntry)
=> {
fileEntry.createWriter((writer) => {
writer.onwriteend = () => {
console.log('file written');
};
writer.onerror = (error) => {
console.error('WRITE ERROR', error);
};
writer.write(new Blob(['Hello!'], { type: 'text/plain'}));
});
}, (error) => {
console.error('FILE OPEN', error);
})
}, (error) => {
console.error('DIR READ', error);
});
};
function onDeviceReady() {
// Cordova is now initialized. Have fun!
console.log('Running cordova-' + cordova.platformId + '@' +
cordova.version);
document.getElementById('deviceready').classList.add('ready');
testFiles();
}
```
The above code writes the file and can be observed by using `adb pull
/storage/emulated/0/Download/test1.txt ./` that both the file exists and
contains the contents written.
Tested against target API 32 / API 32 emulator. Can you please compare, or
share some code that reproduces the issue?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]