Hypothesis: I have thousands of images into different folders in an amazon S3 bucket. I'd like to make them accessibile to unlogged users as slideshow, but I don't want to deal with db and server poor performance (in case of too many users at the same time) , so I'd like to use only javascript.
The problem is that I should however deliver to the client the file list, since I can't use XMLHttpRequest to fetch and parse the xml file that Amazon provides when you try to browse a bucket because (I expect) the browsing page should be located on my webserver.
I think I should write some server-side code to create,after every upload/modification, an updated filelist to share with users, but I'm not sure it's a good idea.
Can anybody suggest me the best way to proceed?
Happy New Year!
Possible answer, tell me what do you think about:
Amazon provides ListBucket operation http://docs.amazonwebservices.com/AmazonS3/latest/API/SOAPListBucket.html
I can choose how many results to get at once using max-keys and marker (for pagination) parameters (example: http://download.terracotta.org/?max-keys=5).
I will obtain a xml file (as smallas I want) that I can parse locally with js in a "list.html" file, for example.
I could then include this list.html file (that should print just the definition of an array of images) in a iframe included in my slideshow.html file on my webserver.
Too dirty?
The Amazon S3 JavaScript API has a method, bucket.list() that will list the contents of a bucket.
Related
I want to make a code using only JavaScript or/and jQuery to access a static directory and retrieve the names of some icons i saved there (SVG icons) and display the names to the user. i couldn't do that with the file api and i have no idea where to start.
I'm going to assume from your mention of jQuery and the File API that you're trying to do this within a browser.
You can't. It just isn't allowed, there is no mechanism to provide it.
If you're in control of the machine where you want this information to be accessed, you can run a server process on it that can do that; code in the browser can then make a request to the server code to request the information. But there's no browser-only way to do it.
So I am trying to figure out how to download an array of images to a users computer. I have been storing everything through calling my server as I feel more secure using firebase on the server. So on click of a button on the client I can get a return of an array of the images in my firebase storage bucket.
Button click -> call server -> get a return of the array of urls from firebase
Now is there a way to download these to the users computer? Prompt them to choose a file path or download them directly?
I know I can do a single download auto by this:
var a = $("<a>").attr("href", url).attr("download", "img.png").appendTo("body");
a[0].click();
a.remove();
I have tested a single url download that auto downloads on the button click, but I dont feel like I should have to loop through the array one at a time to download all nor do I know if this would work. I would assume it would since a single url works.
Is there a better way?
There is no way to download multiple files in one request from Firebase Storage. If you want to allow downloading of multiple files, you'll have to store them in a single (say zip) file and use the approach you already do today for downloading that file.
Alternatively you can use the Google Cloud Storage API to download a bunch of files. See this answer for more on that, but be aware the the Google Cloud Storage API is meant for use on an app server and not directly in your web page.
Environment:
html5
JavaScript
Angularjs
node.js
express.js
Couchbase
Question:
I understand the concerns and security measures implemented within the web environment to prevent the display of directory paths to the world. However, I have an issue that requires knowing the full directory path to a selected file.
I am building a web page for an internal website. The web page needs to allow the user to select a tab delimited file. This tab delimited file will exist on a network server, which is a policy instituted by the company and mandated by external auditors. This file may exist for various clients, with data specific to the client. With that said, the files will reside within different folder structures on the server(s). The user wants to pick the appropriate file and have the data uploaded to the database. Based on the size of the file (up to 10’s of millions of rows), the user does not want to wait for the web page to process immediately. Therefore, the solution is to create a task. The task will contain all the parameters necessary to manipulate the data prior to uploading the data to the database. I understand the simple solution is to upload the file to a common directory but that is not practical. As the user could set up several tasks that will upload the same tab delimited file to the database using different parameters.
I would like to have my task creation process contain the file name with the directory structure. When the background process executes the task, it can extract the data from the original location. Additionally, if I have multiple tasks extracting the same data, I not concerned I may have multiple copies of the data present.
I will appreciate any help with code snippets, website, etc. that may suggest methods to resolving this issue. Please not, that at the current moment, PHP is not an option. A management decision prevents the use of PHP.
TIA
Anthony
It is not exactly possible, so I see two solutions. One is to try and get the path to the temporary location of the file, rather than the actual permanent location.
Suppose your has an id of fileInput and you're using jQuery:
$('#fileInput').change( function(event) {
var tmppath = URL.createObjectURL(event.target.files[0]);
console.log("Temporary Path(Copy it and try pasting it in browser address bar):"
console.log(tmppath);
});
Otherwise I would just make a separate input for path, and show a brief instruction to users on how to copy-paste the URL from their Windows Explorer window.
I need to fetch complete the path from file select element of HTML using JavaScript. I have returned a JavaScript function, but it fetches only file name not the complete path.
How can I get the complete file path?
You can't. It's due to security. The browser only provides the content and the filename.
Providing the path could allow an attacker to learn things about the files on your hard drive that they want kept private. Do you really want to let the web server know that the kitty.png you are uploading for your avatar was actually in c:/pr0n/?
No, I didn't think so.
My web app allows users to record their geolocation data. I need to somehow get that geolocation data into a file so I can put it in s3 storage. I have no idea how to go about this, but the controller already has file uploads to s3 set up using paperclip.
Is there some way to generate a file with javascript and then attach that file when the user clicks save? The other option I was thinking is that I could add a bunch of strings to the body using jQuery .data() method, but then I don't know how to attach a string as a file in my rails 3 form.
Any help is appreciated.
maybe you should try out Amazon's simple db instead of s3 for this? It would be more appropriate than creating files to store data in s3.
Amazon recently released a ruby sdk for their web services, SDB included:
https://github.com/amazonwebservices/aws-sdk-for-ruby
Edit: Or better yet, forget using SDB directly. I had forgotten that that SDK includes an implementation of ActiveModel called AWS::Record. Should make this trivial.
I'm assuming you're on Heroku or something and don't have a method of data persistence?
edit: looking quickly at paperclip's assign method, there's a chance this would work.
yourmodel.your_paperclip_attachment = StringIO.new(params[:your_posted_geolocation_data])
Paperclip appears to handle creating a tempfile from the stream.