Skip to content

Commit 059119d

Browse files
Ron RadtkeRon Radtke
Ron Radtke
authored and
Ron Radtke
committed
applying manual changes for writeFile with content uri
1 parent 3170c65 commit 059119d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilStream.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,15 @@ else if (resolved == null) {
148148
* @param callback Callback
149149
*/
150150
void writeStream(String path, String encoding, boolean append, Callback callback) {
151+
String resolved = ReactNativeBlobUtilUtils.normalizePath(path);
152+
if (resolved != null)
153+
path = resolved;
154+
151155
try {
152156
File dest = new File(path);
153157
File dir = dest.getParentFile();
154158

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

171-
OutputStream fs = new FileOutputStream(path, append);
175+
OutputStream fs;
176+
if (resolved != null && path.startsWith(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET)) {
177+
fs = ReactNativeBlobUtilImpl.RCTContext.getAssets().openFd(path.replace(ReactNativeBlobUtilConst.FILE_PREFIX_BUNDLE_ASSET, "")).createOutputStream ();
178+
}
179+
// fix issue 287
180+
else if (resolved == null) {
181+
fs = ReactNativeBlobUtilImpl.RCTContext.getContentResolver().openOutputStream(Uri.parse(path));
182+
} else {
183+
fs = new FileOutputStream(path, append);
184+
}
172185
this.encoding = encoding;
173186
String streamId = UUID.randomUUID().toString();
174187
ReactNativeBlobUtilStream.fileStreams.put(streamId, this);

0 commit comments

Comments
 (0)