Is it possible to list all files in given GridFS directory using ruby mongo driver?
I've searched through documentation and have not found anything satisfying. What is more I cannot find any way to search files by metadata too.
I have checked java driver's documentation and both of these functionalities are available out of the box using GridFS class.
Best regards,
Michał
grid = Mongo::Grid.new(Mongoid.database)
files = grid.instance_variable_get :#files
files.find("filename" => "uploads/143-normal_regular2.jpg").as_json
# files.remove - deletes alle files
same works for chunks
Related
I am new to Parse Server (implementing it on Heroku and locally).
I have a basic question, when I upload a file using the ParseFile class, it provides me a URL and a fileobject. Where is this File being stored?
Is it being stored physically on a file system? Or in Mongodb?
Thank you!
I found a collection in Mongodb named fs.files. The files I uploaded were located there. I assume the Parse URL is generated as a redirect.
I'm trying to decide where the 'correct folder' to store documents and logs created by my windows form application. The application is used in education and has all paths held in the SQL server. Some (like logs file paths are shared) are accessible on network but specifically for temporary documents where should I default the storage to? I've recently tried the Users/username/AppData/ folder but I seem to be getting differing results after installation; so far I have put this down to people user credentials as often in schools they can do whatever they want (yes I know shocking indeed).
If anyone can point me in the direction of an MSDn article or knows better please reply - Thanks.
** Edit 10/09/2013 - Sorry all I should be further explicit. I'm looking for the folder / structure Microsoft has designed for this sort off activity. My application already provides users with the ability to create thier own working directories (there are several required) but I'm keen to use the 'correct' locations for this sort of activity... I thought the right place would be c:/Users/USERNAME/Appdata/APPLICATION FOLDER/ but as I mention I've come across a few access rights issues when uses install the application.... hope that explains better - thanks
To create temporary directory you can use something like this:
public string GetTempDirectory() {
string path = Path.GetRandomFileName();
Path.Combine(Path.GetTempPath(), path);
Directory.CreateDirectory(path);
return path;
}
Path class info
Directory class info
I have a Sinatra application hosted on heroku and I'm trying to enable file uploading. I know heroku doesn't allow saving to the file system so I'm trying to save the image to MongoDB using GridFS directly. But I don’t know how.
Using the code below, I'm able to save to file system
base_dir = Dir.pwd + "/static/images/channels/"
File.open("#{base_dir}" + params['logo'][:filename], "w") do |f|
f.write(params['logo'][:tempfile].read)
end
How do I save the file directly to MongoDB without first saving it to the file system?
You can use the GridFS API to basically do what you're doing above, but write to MongoDB: http://api.mongodb.org/ruby/current/Mongo/GridFileSystem.html#open-instance_method.
I think you need to upload the file as binary data to a database.
You can use PaperClip to upload files and then store them as binary to MangoDB.
here this link might help you out:
If your files are actually less than 16 mb, please try using this Converter that changes the image of format jpeg / png to a format of saving to mongodb, and you can see this as an easy alternative for gridfs ,
please follow this github repo for more details
https://github.com/saran-surya/Mongo-Image-Converter
I see alot of examples on how to write data from an app to a file then put it in isolated storage. I do not want to write any data to my xml file, I just simply want to save it into isolated storage then query it later.
A few simple questions
Someone have code on how to put an existing xml file into isolated storage. Also since I am not writing to this file, do I need isolated storage still? Can I just add the xml to my project and use Linq to xml to open it query it and close it on a button click?
I wanna query the xml through my application in the background. I see alot of examples on serializing, do I need to do this? Can I just open the xml file and use linq to xml to query the data?
Can I just do this, set bbxml.xml to Content and forget about isolated storage and just do this?
using (XmlReader reader = XmlReader.Create("bbxml.xml"))
{
XDocument xml = XDocument.Load(reader);
//query xml....
}
Include the XML file in your project files in Visual Studio, then in the Properties window make sure Build Action is set to Content and Copy to Output Directory is set to Copy always or Copy if newer. This will include the file in the output XAP file.
To access this file in code use:
XDocument doc = XDocument.Load( "path/to/my/file.xml" );
Of course, it doesn't have to be XDocument, you can use any XML reader class similarly.
I'm working on my first ORM project and am using Mechanize. Here's the situation:
I'm downloading a zip file from my website into a Mechanize::File object. Inside the zip is a file buried three folders deep (folder_1/folder_2/file.txt). I'd like to pull file.txt out of the zip file and return that instead of the zip file itself.
My first thought was to use zip/zipfilesystem. I can do this fine if I save the file to the disk first and use Zip::ZipFile.open(src) but can anyone tell me how/if it is possible to send it over straight from the Mechanize::File.body.
My gut says this has to be possible and I'm just missing something basic. I tried...
zipfile = Mechanize::File.body
Zip::ZipFile.open(zipfile)
...but from what I can tell Zip::ZipFile is only set up to locate a source from a filesystem.
Any direction would be very appreciated and let me know if there are any questions
Thanks in advance
Rob
It seems what you want to do is not possible with rubyzip. From rubyzip library's TODO file:
SUggestion: ZipInputStream/ZipOutputStream should accept an IO object in addition to a filename.