Git Product home page Git Product logo

Comments (4)

thomasvidas avatar thomasvidas commented on August 15, 2024 4

I think the default behavior should not overwrite existing files, but I wouldn't be opposed to adding an option to HttpDownloadFileOptions so that you can overwrite files

from http.

Nazirovich avatar Nazirovich commented on August 15, 2024

I faced the same issue so as a workaround I've added Date.now() before the fileName:

const ret = await Http.downloadFile({ url: url, filePath: Date.now().toString().concat('-', file.fileName), fileDirectory: FilesystemDirectory.Documents });

from http.

nhh avatar nhh commented on August 15, 2024

I am facing the problem, that the file already exists, which is ok - but it seems it is happening with a temp file name.


File Dest file:///Users/nhh/Library/Developer/CoreSimulator/Devices/9EDFDA33-B1E3-4536-9D9D-200C64EF05A1/data/Containers/Data/Application/4CC14443-7988-45D7-A840-3E63EF3B2CB8/Documents/my-file-name.png

ERROR MESSAGE:  {"code":"DOWNLOAD","message":"Unable to download file","errorMessage":"“CFNetworkDownload_rBTFUb.tmp” couldn’t be moved to “Documents” because an item with the same name already exists."}

⚡️  [error] - {"code":"DOWNLOAD","message":"Unable to download file","errorMessage":"“CFNetworkDownload_rBTFUb.tmp” couldn’t be moved to “Documents” because an item with the same name already exists."}

I am also explicitely handle the "it already exists" case, but it seems not to work initially.

const fileName = "Defined elsewhere";

try {


  // stat throws, so we need to try catch
  await Filesystem.stat({
    path: fileName,
    directory: FilesystemDirectory.Data,
  });

  const uri = await Filesystem.getUri({
    path: fileName,
    directory: FilesystemDirectory.Data,
  });

  return Capacitor.convertFileSrc(uri.uri);
} catch (e) {
  // File could not be found, going on...
}

While I am writing this, I noticed, there could be two images in my list, which are the same, which initially don't exist and therefore being tried to download.... twice.

Thank you all for being my rubber-duck. :)

EDIT: I am thinking about a solution, unfortunately without the override option, I need to manually deduplicate my list of images which initially dont exist. This is hard because I am not in control of "load a list" I am either doing, it on the fly.

A workaround would be to append a Date.now() to the file name, but that completely destroys the purpose of saving images on the disk (imo). It also pollutes my clients phones with duplicates.

Do you guys have any idea?

from http.

muuvmuuv avatar muuvmuuv commented on August 15, 2024

Quick fix

    try {
      await Filesystem.stat({
        directory: options.fileDirectory,
        path: options.filePath,
      })
      await Filesystem.deleteFile({
        directory: options.fileDirectory,
        path: options.filePath,
      })
    } catch {
      // noop
    }

I hope this will be fixed with HTTP included in window.fetch...

from http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.