(path: string, copy: boolean = false)
| 313 | } |
| 314 | |
| 315 | public static fromPath(path: string, copy: boolean = false) { |
| 316 | const onError = function (error) { |
| 317 | throw error; |
| 318 | }; |
| 319 | |
| 320 | if (__ANDROID__ && copy) { |
| 321 | if (path.startsWith('content:')) { |
| 322 | const fileInfo = getFileAccess().getFile(path, onError); |
| 323 | // falls back to creating a temp file without a known extension. |
| 324 | if (!fileInfo) { |
| 325 | const tempFile = `${knownFolders.temp().path}/${java.util.UUID.randomUUID().toString()}`; |
| 326 | org.nativescript.widgets.Async.File.copySync(path, tempFile, getNativeApp<android.app.Application>().getApplicationContext()); |
| 327 | path = tempFile; |
| 328 | } else { |
| 329 | const ext = fileInfo.extension; |
| 330 | const name = `${fileInfo.name.replace(`.${ext}`, '')}.${ext}`; |
| 331 | const tempFile = `${knownFolders.temp().path}/${name}`; |
| 332 | getFileAccess().copySync(path, tempFile); |
| 333 | path = tempFile; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | const fileInfo = getFileAccess().getFile(path, onError); |
| 339 | if (!fileInfo) { |
| 340 | return undefined; |
| 341 | } |
| 342 | |
| 343 | return createFile(fileInfo); |
| 344 | } |
| 345 | |
| 346 | public static exists(path: string): boolean { |
| 347 | return getFileAccess().fileExists(path); |
no test coverage detected