Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed file moving #114

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,16 +599,36 @@ static void mv(String path, String dest, Callback callback) {
callback.invoke("Source file at path `" + path + "` does not exist");
return;
}

//Check if the output file directory exists.
File dir = new File(dest);
if (!dir.exists())
{
dir.mkdirs();
}

try {
boolean result = src.renameTo(new File(dest));
if (!result) {
callback.invoke("mv failed for unknown reasons");
return;
InputStream in = new FileInputStream(path);
OutputStream out = new FileOutputStream(dest);

//read source path to byte buffer. Write from input to output stream
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) { //read is successful
out.write(buffer, 0, read);
}
in.close();
out.flush();

src.delete(); //remove original file
} catch (FileNotFoundException exception) {
callback.invoke(exception.toString());
return;
} catch (Exception e) {
callback.invoke(e.getLocalizedMessage());
callback.invoke(e.toString());
return;
}

callback.invoke();
}

Expand Down