Comments (12)
Use createDocument
for one time download to a folder.
You can return if the download is cancelled? I don't see the download related code here? Another way would be to delete the file if it was written possibly. Otherwise do nothing.
from react-native-scoped-storage.
Use
createDocument
for one time download to a folder.You can return if the download is cancelled? I don't see the download related code here? Another way would be to delete the file if it was written possibly. Otherwise do nothing.
Hi Thx for the reply also thx for suggestion the createDocument
but the problem exists also with this function
here is what is missing in such function please have a look you
the problem is that you just assume the ideal scenario and not thinking if something go wrong to reject the promise such as user just navigate back to the app with back button
https://github.com/ammarahm-ed/react-native-scoped-storage/blob/d5c1d75312f84915a096d5b665490aa762a3e905/android/src/main/java/com/ammarahmed/scopedstorage/RNScopedStorageModule.java
public void createDocument(final String fileName, final String mimeType, final String data, final String encoding, final Promise promise) {
try {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_TITLE, fileName);
intent.setType(mimeType);
if (activityEventListener != null) {
reactContext.removeActivityEventListener(activityEventListener);
activityEventListener = null;
}
activityEventListener = new ActivityEventListener() {
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) {
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
if (intent != null) {
Uri uri = intent.getData();
DocumentFile dir = DocumentFile.fromSingleUri(reactContext,uri);
try {
byte[] bytes = stringToBytes(data, encoding);
OutputStream os = reactContext.getContentResolver().openOutputStream(uri);
try {
os.write(bytes);
} finally {
os.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
WritableMap params = Arguments.createMap();
params.putString("uri", dir.getUri().toString());
params.putString("name", dir.getName());
params.putString("type", dir.isDirectory() ? "directory" : "file");
if (dir.isFile()) {
params.putString("mime", dir.getType());
}
params.putDouble("lastModified", dir.lastModified());
promise.resolve(params);
}
/*MISSING*/
else{
promise.reject();
}
/*END*/
}
/*MISSING*/
else{
promise.reject();
}
/*END*/
reactContext.removeActivityEventListener(activityEventListener);
activityEventListener = null;
}
from react-native-scoped-storage.
Nothing will happen if the user navigates back in the app after selecting the folder. The code will execute and complete. I don't see any problem. It's working great in a production app for me.
from react-native-scoped-storage.
Nothing will happen if the user navigates back in the app after selecting the folder. The code will execute and complete. I don't see any problem. It's working great in a production app for me.
yes exactly not after selecting a folder I mean before selection
- user starts to download
- after download the file tree opens (createDocument )
- the user now must select a folder to put the file in ( createDocument )
- here the user would not select any folder but only press the nav back button until the root folder and then form the document tree to app and the app is still waiting for state for the user to select a folder to put the file
this problem can be resolved by adding the else I mentioned
from react-native-scoped-storage.
Nothing will happen if the user navigates back in the app after selecting the folder. The code will execute and complete. I don't see any problem. It's working great in a production app for me.
yes exactly not after selecting a folder I mean before selection
- user starts to download
- after download the file tree opens (createDocument )
- the user now must select a folder to put the file in ( createDocument )
- here the user would not select any folder but only press the nav back button until the root folder and then form the document tree to app and the app is still waiting for the user to select a folder to put the file
this problem can be resolved by adding the else i mentioned
It is already handled. It will return null if there is no folder selected.
from react-native-scoped-storage.
Nothing will happen if the user navigates back in the app after selecting the folder. The code will execute and complete. I don't see any problem. It's working great in a production app for me.
yes exactly not after selecting a folder I mean before selection
- user starts to download
- after download the file tree opens (createDocument )
- the user now must select a folder to put the file in ( createDocument )
- here the user would not select any folder but only press the nav back button until the root folder and then form the document tree to app and the app is still waiting for the user to select a folder to put the file
this problem can be resolved by adding the else i mentioned
It is already handled. It will return null if there is no folder selected.
here is the control line
const CreatedFile = await createDocument(filename, '*/*', buff, 'base64');
console.log(CreatedFile);
the line console.log(CreatedFile);
would never be invoked/executed
from react-native-scoped-storage.
Nothing will happen if the user navigates back in the app after selecting the folder. The code will execute and complete. I don't see any problem. It's working great in a production app for me.
yes exactly not after selecting a folder I mean before selection
- user starts to download
- after download the file tree opens (createDocument )
- the user now must select a folder to put the file in ( createDocument )
- here the user would not select any folder but only press the nav back button until the root folder and then form the document tree to app and the app is still waiting for the user to select a folder to put the file
this problem can be resolved by adding the else i mentioned
It is already handled. It will return null if there is no folder selected.
Hi Did you try the code i sent ?
from react-native-scoped-storage.
@projectnetworld Can you try the master branch and see if it is working as expected now?
yarn add https://github.com/ammarahm-ed/react-native-scoped-storage.git
from react-native-scoped-storage.
@projectnetworld Can you try the master branch and see if it is working as expected now?
yarn add https://github.com/ammarahm-ed/react-native-scoped-storage.git
Hi
yes it works as expected now ,the null is now returned thx for the fix
from react-native-scoped-storage.
How to create directory without using openDocumentTree() method and also how to get path for create directory.
from react-native-scoped-storage.
@gkasireddy202 You can't. that's how scoped storage works. You can't just access stuff without acquiring permissions first. To get path for a directory, use openDocumentTree
from react-native-scoped-storage.
I am using below code for acquiring permissions but below error is occurred.
Can you please share example code for acquiring permissions and create directory.
'/storage/emulated/0'does not have permission to create directories - This error is occurred by using below code for creating the directory in external storage.
createDirectory=async()=>{
const path = ${RNFS.ExternalStorageDirectoryPath};
try {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE );
if (granted == PermissionsAndroid.RESULTS.GRANTED)
{
ScopedStorage.createDirectory(path, "TEST").then((obj) => {
alert(obj)
})
.catch(error => {
console.log("ERROR" + error)
})
} else {
console.log('permission denied');
}
} catch (err) {
console.warn(err);
}
}
from react-native-scoped-storage.
Related Issues (20)
- Questions about Read/Write access HOT 2
- Files is saved empty to the download folder HOT 7
- How to ask permission for specific folder HOT 12
- How to read file .. HOT 1
- "Error: does not have permission to read/write" HOT 1
- new improvements HOT 2
- Multiple File Selection
- Create file using file data HOT 1
- export `exists()` from native module
- Download file from API HOT 8
- Is it possible to copy a file from normal Android file storage into scoped storage? HOT 11
- How to read all files from a folder HOT 2
- deleteFile deletes the entire directory it is in when attempting to only delete one file HOT 1
- How to open a file using default android app HOT 1
- Unexpeted behaviour while writting to a file
- Cannot read property 'openDocumentTree' of undefined HOT 4
- How to enable Manage access to all files
- How to copy image file from one folder to another? HOT 1
- getPersistedUriPermissions returned is difference from openDocumentTree value HOT 3
- await ScopedStorage.copyFile crashes file HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-scoped-storage.