I use FilePicker (now called FileStack) and I wanted to know if it's possible to prevent duplicate file uploads to a single container. For example, if I allow users to up upload some music files, how do I prevent them from adding the same music file twice in the same upload instance? The starter code is below:
filepicker.pickAndStore(
{
mimetype:"image/*",
multiple: true
},
{
location:"S3"
},
function(Blobs){
console.log(JSON.stringify(Blobs));
}
);
To only reliable way for finding duplicates would be compare files MD5 hashes.
MD5 hash is a unique identifier and it is available via filepicker API.
Example call:
https://www.filepicker.io/api/file/hFHUCB3iTxyMzseuWOgG/metadata?md5=true
Response:
{"md5": "f31dbf9b885e315d98e136f1db0daf52"}
To be even more reliable you can also compare file size.
So what I would recommend is storing md5 hash and files size together with file links in the database.
Related
Is there any way on Android 11, except asking for MANAGE_EXTERNAL_STORAGE permission, to get readable File.class of some, non-media, file?
Using Storage Access Framework and DocumentFile I can get Uri (both canRead and canWrite return true), but when I convert it to File, both canRead and canWrite return false (exists return true).
Files my App is using are large SQLite databases created by Users on their computers, which I only read (if it makes any difference), but in order to do that, I need File, instead of Uri.
Currently, my options are:
Asking my Users to find some way to copy files directly to data/data directory (which is not visible to computers and most file managers)
Copying files (using input/output stream) to data/data directory (which means that 500MB file will take 1GB of internal storage on Device)
Applying for MANAGE_EXTERNAL_STORAGE permission, which I doubt Google will approve
Am I missing something?
I am trying to create an app where users can upload files to the "wall". The idea is not important. Each file is added both to storage and to database as [fileName : url) under user's profile. Because of limitations regarding strings in database, I keep filenames without extensions (can't use dot symbol). Uploading works fine but I have a problem with deletion. Based on the file user picks to delete in app I get the filename(without extension). My delete function should delete the file from storage but it cannot locate file because of missing extension.
I use this function to upload the data:
let uploadTask = ref.putData(contents as Data, metadata: myMetadata, completion: { (metadata, error) in ...}
and the file itself:
let contents = try Data(contentsOf: url.standardizedFileURL)
Is it possible to upload "contents" without the extension? Or maybe is there another approach I'm missing?
Thanks for tips.
It's not a really good idea to store the names of random things (including files) as keys in Realtime Database. You could make this easier on yourself by pushing an object at a location in the database for each file uploaded. The pushed object could contain the name and location of the file in Storage, along with any other metadata about that file, and you won't have to mangle that data as long as it's stored in values rather than keys.
I need to play a mp3 file from gridfs in mongodb. I will get a file-like object instead filename (to the system disk).
I cannot find anyway to use SoundLoader to play the file like object directly. I checked the code here https://kivy.org/docs/_modules/kivy/core/audio.html. it seems that kivy audio does not suppot it. Am I right? I mean, like wave module, you can open it with file like object. I prefer not to use wave because it may has issues in different OSs.
wave.open(file[, mode])
If file is a string, open the file by that
name, otherwise treat it as a seekable file-like object.
Any other way to load the data to SouldLoader instead of filename? Many thanks.
This may not be a direct answer but could be an alternative for now. I can use GridFSBucket in GridFS to download the file in stream then save temp file to disk. Finally load by SoundLoader. With this way, it would solve the problem with large media file issue. This solution also works for image or video but require some disk storage of course.
'pickAndStore' method allows me to specify full path to the file, but I don't know it's extension at this point (file path has to be defined before file is uploaded, so it's not possible to provide a path with correct extension).
if I use 'pick' and then 'store' I have 2 files (because both methods uploads file to the s3). I can delete 'old' file, but it's not optimal and can be pain (take ages) with really big files.
Is there any better solution? Ideally to rename existing file.
Currently, there is no workaround for renaming file.
However, in our Javascript API v2 we are planing to add new callback function. onStart callback will be fired after user pick file but before file uploading. There could be option like renaming file based on original filename.
We will keep you updated.
I'm evaluating the InkFilePicker service. How do I make sure that uploading a new file to my S3 bucket won't overwrite an existing file with an identical name already in that bucket?
I'm currently using another third party upload solution that allows me to rename a file with a GUID as its file name to prevent such accidental overwrite situations.
How do rename files using InkFilePicker? Or what is the right approach with InkFilePicker to prevent unintended overwrites?
Thanks,
Sam
Looks like InkFilePicker prepends a unique key to file name during upload.
myfile.pdf becomes something like DNjimbeSQWVrcd0Uv8lJ_myfile.pdf when it's saved on Amazon S3 so it inherently prevents overwrites.