Comments (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.
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.
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.
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)
- if http is not maintained, then what is the recommended plugin? HOT 2
- Allow fragments to be parsed as JSON in response data
- Could not cast value of type '__NSCFNumber' (0x10881b608) to 'NSString' (0x1f473fc40). HOT 1
- Allow WebDAV HTTP methods
- Sending request on background HOT 2
- Setup custom values in header not work.
- Request to https domain fails with SSLHandshakeException. HOT 5
- cannot overwrite default request headers on ios
- JSONException on device when getting a primitive value, e.g. number
- [feat] support metadata for uploadFile HOT 1
- downloadFile method not working correctly on Android
- Http progress listener has serious performance issue on Android HOT 3
- Cannot get cookies in the response
- iOS and Android handle form-uurlencoded requests differently HOT 2
- How to write interceptor in capacitor http HOT 1
- https url is not hitting with http-community in IONIC React. HOT 1
- Capacitor v4 support? HOT 4
- setCookie: "errorMessage":"Must provide value"
- Capacitor 4 : Http urls not working (only https) HOT 2
- Unable to open asset URL on Android
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 http.