Unzipping a file in node.js to a url path - javascript

I'm making an application in the express framework where the user uploads a zip file and views it on the website. I already have uploading a single html file and viewing it; however, I can't seem to figure out extracting a zip file online. I can currently store the zip file in the database, but when it's pulled from the database it seems to be impossible to unzip it in to the url and not on my disk. Where do you think I should start with trying to solve this problem?

I suggest the use of this module: https://github.com/cthackers/adm-zip - I have succeded in using it when user uploads file that must be unziped at server side. I think that docs for the native zlib API are missing or not yet supplied. Let me know if this helps

Not sure which zip format you're using, but one example of how it could work is with the zlib api: http://nodejs.org/api/zlib.html
If you use that library to create a stream you can write that stream to the response, in concept. The bigger question in my mind is what do you mean by "unzip to a url"? If the zip is an archive w/ multiple files, what do you expect a user to see at that URL?

Related

How to fetch data as .csv file from client with node.js application

i have written a game in javascript with the p5.js library. Now i want to host the game on a server to conduct a survey on a service like amazon turk. Ideally the clients recieve a URL to the game and play it while in-game actions are tracked and stored in node.js or on the server and exported as a .csv file once they are done playing. After they finish the game the csv. file should be sent automatically to a location that i can then access. I have zero experience in server hosting or similar topics.
So a couple questions arise:
Is a hosting service like Heroku suitable for hosting the game?
Do i need to use node.js to make this happen?
Which of those two would extract the data and store it to a csv? And where is the file stored?
How do i get or access the csv. after?
Any alternative takes to solve the problem?
Thanks alot in advance!
github repository: https://github.com/luuuucaaa/schaeffers-charade
game on github pages: https://luuuucaaa.github.io/schaeffers-charade/
If I were you, I would do it like below:
Host
Since your project is basically a html & JavaScript static contents,
AWS S3's static hosting would be sufficient (Also, the current git hub pages is another option if you just want to host it).
Hosting on node.js environment is also available using webpack serving, but it requires additional works. (but if you require other npm packages to generate .csv file, you need webpack anyway to bundle js file and attach it to html)
Data Storing
Two ways are considerable,
the first is to store it on the filesystem. Generate .csv via JS script within your app, and save it where the app is hosted (if you go with s3, you can access it afterwards, but I'm not sure if it can write objects by script)
The second is to post the data to another API endpoint. (for example building an API Gateway on AWS that triggers Lambda, which stores it on S3)
It's merely an example and I don't know exactly what you want to achieve, but take it into considerations. Good luck. Cool game BTW.

Mulit-part download from S3 bucket with Angular

I want to do a multi-part download from S3 for large files (1 Gb+) using Angular. There is a lack of documentation and I haven't found a single example which explains this in detail.
Enough documentation available for multi-part upload.
I am using s3.getObject() method from aws-sdk.
I know that we can get a chunk by passing the Range parameter to s3.getObject(). I need help on how to pass these range for large files, how to maintain the chunks and how to combine all of them at last.
Let's say I have the user authenticated and I wish to download a large file from private S3 bucket in multi-part for faster downloads. Any help is appreciated.

Nodejs file download via client (client act as 'middleman' between server and file)

First off, I know this seems illogical when I could just send the download URL to the server. The issue with that is that user's can access these download links and so for those who can I need to be able to download it. I can't really explain why as I am under NDA.
I am trying to download a file from a URL via the client (browser) and stream the data directly to the server where the file is saved so the client essentially acts as a "middleman" and does not require the file to be downloaded to the client's machine.
I have been experimenting with "socket.io-stream" and "socket.io-file" but i am having a few issues with both. "socket.io-stream" allows me to upload a specific file from the client to the server but the uploaded file has a size of 0kb and doesn't have any examples on Github.
"socket.io-file" has examples, which I followed and currently have it setup so I can use an input tag to select a file to upload to the server successfully.
From what I can see the "socket.io-file" upload function takes a file object as the parameter.
So I have two questions really:
Is there a plugin for JS (Browser) & NodeJs (Server) that would allow me to do this?
or
How can I create a File Object from an external url?
I solved this is the end, using a chrome extension to download the file as a blob object, pass the object to the content script and then use socket.io-stream to upload it to the server.

Local .xml file converted to JSON with JavaScript

I'm working in a node JS REST service. All the endpoints are almost done.
I have created a simple web page where the user can introduce a .gpx file (xml) and with the module xml2json convert it into json format.
I have tried the function using a local path and works, but my problem comes when I deploy the application into a web service, Javascript can not take the local file path to convert the file and store the JSON into the database.
I don't know how to proceed. Should I upload the file into my server and after that take the server path and converse the file? ( I donĀ“t need the file so should I delete after the conversion?)
Could I converse the file without upload to the server?
Help me please with some clues to proceed.
Thank you all in advance!

Upload File/s From Client To Azure Blob Storage | MVC

I have WebApp(MVC4) with a file upload and I did a terrible mistake, I let the client upload files to my server(Virtual Machine Azure) directly.
In order to do it, I set (in the WebConfig) :
maxRequestLength="2097151"
executionTimeout="3600"
maxAllowedContentLength="4294967295"
Now I understand that its not the way to do it.
So what I want is to be able to upload the user files directly to my Azure Blob Storage without the files getting to my site.
I manage to upload files to my storage with C# butI don't want to send the files to the server-side and taking care of them there, because its mean that the files are first upload to the server then they move to the blob storage, and this is not good for me because I'm dealing with a very large files.
I need to transfer the files to the blob storage without going through the server.
How can I do it ? I didn't manage to find too many article addressing this issue, I just read about SAS and CORS that helping addressing the problem but without actual guidelines to follow.
You are right that CORS and SAS are the correct way to do this. I would recommend reading Create and Use a SAS with the Blob Service article for an introduction. Please also see our demo at Build 2014 for a sample application that lists and downloads blob in JavaScript using CORS and SAS.

Categories