download file from s3 as csv by means of javascript - javascript

I really think this is trivial one, but I just can't find the right answer.
I have a csv file on s3 bucket. I have link to it, which looks something like:
https://blabla-bucket.s3.amazonaws.com/imaginefolder/testfilename.csv?AWSAccessKeyId=111&Expires=222&Signature=333
Now I want to put a link to it. When user clicks, csv file download should start in his browser.
I tried the following:
<a download href="https://blabla-bucket.s3.amazonaws.com/imaginefolder/testfilename.csv?AWSAccessKeyId=111&Expires=222&Signature=333">Download</a>
And it works, but downloaded file is with txt extension.
I am not sure if the reason is in Amazon API configuration or in the way I am handling this ahref.
I saw that people recommend to use AWSJavaScriptSDK, But I am really interested to know if there is a way to do it by simple means.

Related

Save canvas to an image file dynamically

Is there a way to download a canvas image to a file folder without a prompt showing up? I have found solutions requiring a prompt where you name the file, but I have not found any solutions where you can dynamically name the image and save to a local file. I am very new to front-end development, so I am not entirely familiar with Node.js or JQuery/PHP/Ajax. I have found solutions using these but they have ended up still using prompts.
In general, this is a security feature.
You don't want a site you browsing to save files to your computer silently. They can possibly contain a malicious code for example, or override an existing file. Thus, as a security feature the browsers are asking you to name the file you will save.
There is a way to name the files thou, so you don't need to present the user with generic file name.
On How to do that - it really depends what are you using to do it..
In your situation - if those are log files you want to save - you can send them back to the server. That can be easily done.

How to display a user-uploaded PDF in React using FilePicker from 'react-file-picker'?

My goal is to allow the user to upload a pdf from their file explorer, and upon clicking a button that says 'view', they'll be able to see that PDF file.
I'm currently using react-file-picker to upload files, but that doesn't seem to work.
I know someone is going to comment, "Look it up", or something like that, but I have. All the examples that I've seen so far are only tailored to PDFs that can be found at various online URLs. I'm obviously not using URLs, but instead actual pdfs from the users file explorer.
Currently I have a method for displaying the actual button to use when uploading files, and there's a method attached to it that handles the file after it's uploaded. I need help with the handleFileChange method below so that I can show the pdf. If 'FilePicker' isn't a good option, can anyone provide me with suggestions on good React tools that will help me achieve this?
Thanks for your help!
My code for uploading a file:
Check out the documentation for pdf-viewer-reactjs. It will do what you need and looks to be simple to implement.

Upload file to website, call Python script and download a generated new file in the most lighweight way

I need to solve a problem where I parse a csv file via a Python script and generate a new file. I've written the script, but the tricky part is that the file to be handled needs to be uploaded via a browser and the result downloaded likewise. The idea is that it shouldn't require a webserver, it needs to be something like a folder, where you open index.html, upload a file and get a download prompt for the result and I'm looking for the most lightweight solution (I am aware I could do this with Django or Flask, but a whole framework for a tiny tool seems overkill).
This may be a bit confusing, so I'll try to clarify the first hurdle:
How do I call a python script from a webpage without setting up any webservices (if possible) or what would be the quickest way to achieve this. The webpage isn't really a webpage, it will never be deployed on a webserver, it's just an interface for the script.
For the upload part you can use requests :
How to send a file from a python script
For the download part, do you know the url without having to ask anything to the remote server ? If yes, you can still use requests.

File Upload/Manipulation/Download without use of a server: Is it possible?

I am looking to make a website that does three things:
The user can upload an image to the website (without a server)
-For this problem, I have found resources like Dropzone, but all seem to mandate sending the image to a server.
The uploaded file is manipulated on the client side
-For this problem, I need the uploaded file to be accessible from my JS/HTML code and I need some way for me to manipulate the file. I currently have my website with the pre-set file embedded in it, which I can then access and manipulate with JS, so the manipulation itself isn't much of the issue, but rather just accessing the file.
The user can then download the manipulated file (again, without a server)
-For this problem, I know that how to make a download button for files that have a web address (which are on a server), but is there a way to have a download button for the file that was just manipulated? I found this question here that seems to be a good starting point, but I am not sure if I completely understand the implementation of it.
Basically, I have the website framework in place (using HTML/CSS, Javascript) and I am just looking to see if this is possible to do without the use of a server, even if I have to use some other libraries. If any insight or links to potentially useful articles/libraries could be given on any one of these three points, I would much appreciate it.
Note: If this is not possible without a server, please let me know because then I will have to completely redesign everything and this whole question is trivial.
The user can upload an image to the website (without a server)
A website is typically hosted on a server. I think you mean the image is uploaded, but not stored anywhere.
The uploaded file is manipulated on the client side
There are lots of cool JS libraries to handle this, for something light you can try out https://fengyuanchen.github.io/cropperjs/
The user can then download the manipulated file (again, without a server)
So if I am understanding you are asking for an image upload -> edit -> image download. This is very possible and common. However, you will need somewhere to cache the uploaded image for the client.
If you are asking if you can upload an image directly to the DOM, you can not. You need to upload the image to the location where your files are being hosted. Imagine having an absolute path to C:/MyComputer/MyImage, it would obviously not work on any other machine than your machine.
If you need some examples on how to handle the upload image to temp location -> edit -> download let me know

Hope to create gmail attachment preview like functionality using angularjs

I have a requirement where I want to show the file preview to the users.
There are various file types which are supported like; .pdf, .xlsx, .doc, .rar, .jpeg, .png and many more.
When user clicks on the preview it should open the file in popup where preview of the file is shown to him. User can Zoom-in, Zoom-out, Download the file. Just as you can see into gmail for attachment preview.
Please, can anyone guide me to any relevant library or helpful resource for the same.
Thanks in advance
There are two main ways you can do this.
1) Server-side: Render previews once server-side (on file upload) into jpg/png images, and store the previews on the server. This is the easiest to implement on the client side, but requires extra storage on the server.
2) Client-side: Render the previews 'live' with javascript in browser, this reduces the amount the server has to do/store, but does require the client to fully download the file in-memory before it can render the preview, which for large files could be an issue. Also, you would need javascript libraries included for likely each individual file type, since most libraries will target one specific file format.
Server-Side is probably the recommended way to go. What are you using for your web server?
You are looking at creating document viewer.
Belive me its big work as browser does not understand these formats. Browser can render images directly on canvas but it does not know how to render the other files. So, any file other than image formats, one need to save them temporarily on server and then stream on the browser and show them using the respective file viewer.
You can convert doc and xlsx files to pdf and show these files using pdf viewer (http://ngmodules.org/modules/ng-pdfviewer). There are plenty of document converters available on internet (however you will need to check the licensing terms as most of them are GPL licensed, hense can not be used in commercial projects).
If you want to save this work then go for third party server those take all paint to convert documents in html5 such as https://crocodoc.com/why-crocodoc/
You can also try using google doc viewer google doc veiwer
This question is fairly broad. I'm not going through all the steps of how to implement an attachment viewer directive, but here are some pointers you might find useful.
To allow the user to download the file, you simply put a download link somewhere. If you are hosting the attachment on Amazon S3, Google Cloud Storage or some other cloud storage service, check their documentation. If you're downloading the files from your own server, make sure to set the Content-Disposition HTTP response header to attachment; filename="ORIGINAL_FILENAME", where ORIGINAL_FILENAME is the file name you want to user to see in the save dialog that appears when they click the download link.
Now on to the viewer.
For PDF files, I'd use pdfJS. There's an angular directive for it here.
You could look at something like CloudConvert for other files, to convert ehm to a PDF, and then displaying them in pdfJS, but then you probably want to store the PDF on your server as well, in addition to the original files, which requires extra storage. You might also be able to use the Google Docs viewer, or Office 365 viewer, as described in this answer.

Categories

Resources