You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: android/src/main/kotlin/io/lakscastro/sharedstorage/storageaccessframework/lib/StorageAccessFrameworkConstant.kt
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ const val OPEN_DOCUMENT_TREE = "openDocumentTree"
Copy file name to clipboardExpand all lines: docs/Usage/Storage Access Framework.md
+95Lines changed: 95 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -217,6 +217,33 @@ final DocumentFile? createdFile = createFileAsBytes(
217
217
);
218
218
```
219
219
220
+
### <samp>writeToFileAsBytes</samp>
221
+
222
+
Write to a file using raw bytes `Uint8List`.
223
+
224
+
Given the document uri, opens the file in the specified `mode` and writes the `bytes` to it.
225
+
226
+
`mode` represents the mode in which the file will be opened for writing. Use `FileMode.write` for truncating (overwrite) and `FileMode.append` for appending to the file.
227
+
228
+
```dart
229
+
final Uri documentUri = ...
230
+
final String fileContent = 'My File Content';
231
+
232
+
/// Write to a file using a [Uint8List] as file contents [bytes]
233
+
final bool? success = writeToFileAsBytes(
234
+
documentUri,
235
+
bytes: Uint8List.fromList(fileContent.codeUnits),
236
+
mode: FileMode.write,
237
+
);
238
+
239
+
/// Append to a file using a [Uint8List] as file contents [bytes]
240
+
final bool? success = writeToFileAsBytes(
241
+
documentUri,
242
+
bytes: Uint8List.fromList(fileContent.codeUnits),
243
+
mode: FileMode.write,
244
+
);
245
+
```
246
+
220
247
### <samp>canRead</samp>
221
248
222
249
<samp>Mirror of [`DocumentFile.canRead`](<https://developer.android.com/reference/androidx/documentfile/provider/DocumentFile#canRead()>)</samp>
@@ -485,6 +512,31 @@ final DocumentFile? createdFile = createFileAsString(
485
512
);
486
513
```
487
514
515
+
### <samp>writeToFileAsString</samp>
516
+
517
+
<samp>Alias for `writeToFileAsBytes`</samp>
518
+
519
+
Convenient method to write to a file using `content` as `String` instead `Uint8List`.
520
+
521
+
```dart
522
+
final Uri documentUri = ...
523
+
final String fileContent = 'My File Content';
524
+
525
+
/// Write to a file using a [Uint8List] as file contents [bytes]
526
+
final bool? success = writeToFileAsString(
527
+
documentUri,
528
+
content: fileContent,
529
+
mode: FileMode.write,
530
+
);
531
+
532
+
/// Append to a file using a [Uint8List] as file contents [bytes]
533
+
final bool? success = writeToFileAsBytes(
534
+
documentUri,
535
+
content: fileContent,
536
+
mode: FileMode.write,
537
+
);
538
+
```
539
+
488
540
### <samp>createFile</samp>
489
541
490
542
<samp>Alias for `createFileAsBytes` and `createFileAsString`</samp>
@@ -514,6 +566,49 @@ final DocumentFile? createdFile = createFile(
514
566
);
515
567
```
516
568
569
+
### <samp>writeToFile</samp>
570
+
571
+
<samp>Alias for `writeToFileAsBytes` and `writeToFileAsString`</samp>
572
+
573
+
Convenient method to write to a file using `content` as `String`**or**`bytes` as `Uint8List`.
574
+
575
+
You should provide either `content` or `bytes`, if both `bytes` will be used.
576
+
577
+
`mode` represents the mode in which the file will be opened for writing. Use `FileMode.write` for truncating and `FileMode.append` for appending to the file.
578
+
579
+
```dart
580
+
final Uri documentUri = ...
581
+
final String fileContent = 'My File Content';
582
+
583
+
/// Write to a file using a [String] as file contents [content]
584
+
final bool? success = writeToFile(
585
+
documentUri,
586
+
content: fileContent,
587
+
mode: FileMode.write,
588
+
);
589
+
590
+
/// Append to a file using a [String] as file contents [content]
591
+
final bool? success = writeToFile(
592
+
documentUri,
593
+
content: fileContent,
594
+
mode: FileMode.append,
595
+
);
596
+
597
+
/// Write to a file using a [Uint8List] as file contents [bytes]
/// - `bytes` is the content of the document as a list of bytes `Uint8List`.
321
+
/// - `mode` is the mode in which the file will be opened for writing. Use `FileMode.write` for truncating and `FileMode.append` for appending to the file.
322
+
///
323
+
/// Returns `true` if the file was successfully written to.
0 commit comments