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

File extension not showing (create a file) #3

Open
roccograpisarda opened this issue Apr 28, 2023 · 3 comments
Open

File extension not showing (create a file) #3

roccograpisarda opened this issue Apr 28, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@roccograpisarda
Copy link

hi,
i'm currently developing a flutter app for a Master's degree course related to the developing process like branches usage, etc.
The app basically gives the possibility to keep track of expenses in the plain text accounting way.
I'm developing this app "Plain Wallet" with other 3 my colleagues and we would like to publish it on F-Droid.
rWe recognize the efforts of others so there is no doubt that we are going to mention your package on the about page that is in the app also if we will use the app just for us.

Now i explain why i opened this issue.
I already implemented the select current file by using another package and now i need to create one if the user doesn't upload one.
i was looking for a flutter package to do that found your project which looks perfect for that.
I implemented a method createFile() which create a example.journal in the app folder and then i call the PickOrSave().fileSaver and i pass as filePath the file.path value. when the PickOrSave().fileSaver is called the app shows the file manager and at the bottom a text field where i can specify the file name.
In my case i see "example" and not "example.journal". It happens also if i specify the field fileName.

After saving the file in the selected folder i delete the file which is in the app folder.
I store the path which is in result[0] in the sshared preferences and then

  static Future<void> createFile(
      ScaffoldMessengerState scaffoldMessenger) async {
    bool hasPermission = await prepareStorage();
    if (!hasPermission) {
      return;
    }

    Directory? plainWalletDir = await getExternalStorageDirectory();

    File file = File("${plainWalletDir?.path}/example.journal");
    await file.writeAsString("");
    List<String>? result = await PickOrSave().fileSaver(
        params: FileSaverParams(
      localOnly: true,
      saveFiles: [SaveFileInfo(filePath: file.path, fileName:"file.journal")],
    ));
    file.delete();
    print("file deleted");
    print("result to string: $result");
    String savedFilePath = result![0];
    print("saved savedFilePath value: $savedFilePath");
    storeSelectedFilePath(savedFilePath);
    scaffoldMessenger.showSnackBar(
      const SnackBar(content: Text('File created in the download folder')),
    );
  }

when i tap on the button which uses this function i have this logs:

D/PickOrSavePlugin( 7295): Saving file on background...
D/PickOrSavePlugin( 7295): Saving file '/storage/emulated/0/Android/data/com.example.app/files/example.journal' to '/document/primary:Download/file'
I/gralloc4( 7295): unregister: id=21d00000977
W/libEGL  ( 7295): EGLNativeWindowType 0xb4000076f29b4ef0 disconnect failed
I/gralloc4( 7295): register: id=21d00000978
D/PickOrSavePlugin( 7295): Saved file to '/document/primary:Download/file'
D/PickOrSavePlugin( 7295): ...saved file on background, result: /document/primary:Download/file
I/System.out( 7295): fileSaving result cleared
I/System.out( 7295): Elapsed time in nanoseconds: 49250000
I/gralloc4( 7295): register: id=21d00000979
I/flutter ( 7295): file deleted
I/flutter ( 7295): result to string: [/document/primary:Download/file]
I/flutter ( 7295): saved savedFilePath value: /document/primary:Download/file

As you can see the file is saved but without an extension. I tried to use different extensions like the examples in the flutter package's page but it doesn't show.
The goal is to save the file with the extensionthat in my case is ".journal so the output should be a file created/saved like "name"+".journal" .

Best regards,

Rocco R.

@roccograpisarda roccograpisarda changed the title File extentsion not showing (create a file) File extension not showing (create a file) Apr 29, 2023
@chaudharydeepanshu
Copy link
Owner

Hey 👋,

Thank you for taking the time to open this issue and describing the issue in detail.

The issue you described is due to the fact that currently the plugin used mime types for extensions and if it can't find mime type for a extension then it assigns unknown mime to those files resulting no extension on saved file.

Now, to fix that I just need to attach extension to file name for files with unknown mime type.

So, this is should be a quick fix and I will provide a new update with solution soon (Before Saturday).

@roccograpisarda
Copy link
Author

hi,
thanks for your reply.
i found a solution but by using another way.
Basically i created a page with 2 fields, one to specify the file name and another one which if tapped shows the file manager. How? i used the filesystem_picker plugin which i think is the best if you need to work with files because you can get the real file path. Because i also found that by using the pick_or_save to get the saved file's path i get something like this "/document/primary:Download/file" but the real path should be "/storage/emulated/0/Android/Download".
Which plugin are you using to show the file manager?
Best regards,
Rocco R.

@chaudharydeepanshu
Copy link
Owner

I'm happy that you found your solution.

My plugin uses Android native code to show file manager and uses the SAF access method for all picking and saving files. The benefit of that is we don't need the storage read-write permission in the app (PlayStore is very strict with permissions nowadays). And this approach is what Google suggests if our app is not something like a file manager etc.

Now, when using SAF we can only get and access files with paths like "/document/primary:Download/file". These paths are pretty powerful when using them on the Android native side as they provide direct read-write access to files.

image
https://developer.android.com/training/data-storage/shared/documents-files#create-file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants