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

download error if file exists #620

Closed
chenhucxc opened this issue Mar 26, 2022 · 9 comments · May be fixed by #708
Closed

download error if file exists #620

chenhucxc opened this issue Mar 26, 2022 · 9 comments · May be fixed by #708
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@chenhucxc
Copy link

/**
     * Create a file using java.io API
     */
    private File createFileInAppSpecificDir(String filename, String savedDir) {
        File newFile = new File(savedDir, filename);
        try {
            boolean rs = newFile.createNewFile();
            if (rs) {
                return newFile;
            } else {
                logError("It looks like you are trying to save file in public storage but not setting 'saveInPublicStorage' to 'true'");
            }
        } catch (IOException e) {
            e.printStackTrace();
            logError("Create a file using java.io API failed ");
        }
        return null;
    }

should add this

if (newFile.exists()) {
            return newFile;
}
@Faaatman
Copy link

Faaatman commented May 11, 2022

This error is also happening on Android when the file is in the directory but I'm trying to download it using the downloader.

@hnvn do you think there's a better solution for this? I think it's better to append a duplication number to the file name ex(photo.png, photo(1).png) since different files can have the same file name and rewriting or retrieving the file with the same name isn't the best solution IMO.
I can work on a PR for this fix, I just need your input. :)

@MirzaUkas
Copy link

MirzaUkas commented May 18, 2022

This error is also happening on Android when the file is in the directory but I'm trying to download it using the downloader.

@hnvn do you think there's a better solution for this? I think it's better to append a duplication number to the file name ex(photo.png, photo(1).png) since different files can have the same file name and rewriting or retrieving the file with the same name isn't the best solution IMO. I can work on a PR for this fix, I just need your input. :)

Same problem here, sound nice if you fix this. I agree too, about append a duplication number when the filename is the same

@ebwood
Copy link

ebwood commented May 19, 2022

Create unique locale file with the remote file name: gist

import 'dart:io';
import 'package:path/path.dart' as path;

class FileUtil {
  static File getUniqueFile(String folderName, final String? fileName) {
    int num = 1;

    String destFileName =
        fileName ?? '${DateTime.now().millisecondsSinceEpoch}';

    String extension = path.extension(destFileName);
    String baseName = path.basenameWithoutExtension(destFileName);

    File file = File(folderName + path.separator + destFileName);
    while (file.existsSync()) {
      destFileName = '$baseName (${num++})$extension';
      file = File(folderName + path.separator + destFileName);
    }
    return file;
  }

  static Future<File> createUniqueFile(
      String folderName, final String? name) async {
    File uniqueFile = FileUtil.getUniqueFile(folderName, name);
    if (!uniqueFile.existsSync()) {
      await uniqueFile.create();
    }
    return uniqueFile;
  }
}

@bartekpacia bartekpacia added bug Something isn't working good first issue Good for newcomers labels May 23, 2022
@Kishan-Somaiya
Copy link

Kishan-Somaiya commented Jun 7, 2022

any updates on this ? facing the same issue it fails alternately if file exists.

Edit: Thanks @FaKenKoala for your answer, it really helped me ❤. But I think these cases should be handled by plugin.

@claptv
Copy link

claptv commented Jul 19, 2022

It happens when the task status for the file in the Downloader DB is not 'complete,' but you have a fully downloaded file in the local directory. The problem is that the plugin sees the fully downloaded file as a partially downloaded one. If the same file exists, the plugin resumes downloading and sends the size of the byes to the server, which causes HTTP status 416 Range Not Satisfiable.

We could reduce the size of downloadedBytes by a small amount and resume downloading in the setupPartialDownloadedDataHeader method.

@arthas1888
Copy link

Same problem form me

@bartekpacia
Copy link
Collaborator

@Faaatman Would be great to see your PR fixing this :)

jenseralmeida pushed a commit to jenseralmeida/flutter_downloader that referenced this issue Aug 19, 2022
jenseralmeida pushed a commit to jenseralmeida/flutter_downloader that referenced this issue Aug 19, 2022
jenseralmeida pushed a commit to jenseralmeida/flutter_downloader that referenced this issue Aug 19, 2022
jenseralmeida pushed a commit to jenseralmeida/flutter_downloader that referenced this issue Aug 19, 2022
@bartekpacia
Copy link
Collaborator

This is worked on in #708 :)

@IlyaMax
Copy link

IlyaMax commented Aug 30, 2022

you all have this open failed: EACCES (Permission denied) error? I'm not sure that I have the same issue as you but it seems like that

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

Successfully merging a pull request may close this issue.

9 participants