Skip to content

Commit

Permalink
applying manual changes for writeFile with content uri
Browse files Browse the repository at this point in the history
  • Loading branch information
Ron Radtke authored and Ron Radtke committed Apr 14, 2024
1 parent 3170c65 commit 059119d
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,15 @@ else if (resolved == null) {
* @param callback Callback
*/
void writeStream(String path, String encoding, boolean append, Callback callback) {
String resolved = ReactNativeBlobUtilUtils.normalizePath(path);
if (resolved != null)
path = resolved;

try {
File dest = new File(path);
File dir = dest.getParentFile();

if (!dest.exists()) {
if (resolved != null && !dest.exists()) {
if (dir != null && !dir.exists()) {
if (!dir.mkdirs()) {
callback.invoke("ENOTDIR", "Failed to create parent directory of '" + path + "'");
Expand All @@ -168,7 +172,16 @@ void writeStream(String path, String encoding, boolean append, Callback callback
return;
}

OutputStream fs = new FileOutputStream(path, append);
OutputStream fs;
if (resolved != null && path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET)) {
fs = ReactNativeBlobUtilImpl.RCTContext.getAssets().openFd(path.replace(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET, "")).createOutputStream ();
}
// fix issue 287
else if (resolved == null) {
fs = ReactNativeBlobUtilImpl.RCTContext.getContentResolver().openOutputStream(Uri.parse(path));
} else {
fs = new FileOutputStream(path, append);
}
this.encoding = encoding;
String streamId = UUID.randomUUID().toString();
ReactNativeBlobUtilStream.fileStreams.put(streamId, this);
Expand Down

0 comments on commit 059119d

Please sign in to comment.