Convert blob image urls to Zip file by JSZip - zip

My javascript code return list of images in form of blob urls like blob:http://localhost/93e9b867-ca7b-46cc-82fa-086b571b839e.
I want to make zip file of it through JSZip library.
let zip = new JSZip();
zip.file(what will be the code ?);

Related

How can I create a dataframe from a geojson file inside a zip file?

I have a url which has a zip file, and within that zip there is a geojson file.
I want to create a dataframe using geopandas without having to download the file to my system.
The url is this one:
https://datosabiertos.bogota.gov.co/dataset/397ccbd8-e2c5-4700-b90e-b68d101ab0c5/resource/7e426e92-c168-4a99-ab67-25b16f070a68/download/dcons_geoson.zip

ibm-cos-sdk putObject does not create the correct Binary Object

Following the instructions from the documentation, I try to upload a file on a bucket.
If I upload a text file (i.e. a csv file), everything works as expected.
If I upload a binary string file (i.e. a pdf file) (read using readAsBinaryString), the file on cloud storage is wrong, only blank pages. The file size and the 256hash of the file changes.
I used all:
A buffer Buffer.from(binaryString)
A Uint8Array new TextEncoder().encode(binaryString)
A the binary string
on
putObject({
Bucket: 'test-b',
Key: key,
Body: binaryString
})
Instead of using the binary stream of the file for PDF try to upload using the multipart file upload option to upload it.

How to receive .zip file in Flask from Angular UI?

I have an Angular application in which I used
<input type="file" (change)="fileChanged($event)">
to upload a .zip file.
I get the file like this:
fileChanged(e) {
this.file = e.target.files[0];
}
Now, I want to send this .zip file to my server (Python-Flask) and want to store it as a .zip file on my server-side.
I send the request to server like this:
const fd = new FormData();
fd.append('files', this.file, this.file.name);
fd.append('fileType', 'zip');
this.http.post('/my_app_route1/', this.file,
{headers:{'Content-Type': 'application/zip'}}).subscribe(f => {
....});
To receive and save this, I do the following on my python side.
#app.route('/my_app_route1/', methods=['POST'])
mydata = (request.get_data())
with open('hello.zip', 'wb') as f:
f.write(mydata)
Now, this data is binary data which I do not know how to write to a .zip file from Python.
When I try to print "mydata", I see glimpses of my original .zip file data which I had sent from front end mixed with other symbols.
Am I passing the .zip file right? If not how should I pass it?
Also, how can I save the .zip on my server-side using Python-Flask?
NOTE: The .zip file consists of multiple directories and sub-directories, and I want to replicate the same on my server-side.

How to download the Zip file from express js

I have three files, I have to zip and send, currently I am using archiver to zip them. I am trying to download the .zip file from express js. It prefectly works for text files, apparently it works for zip files even. but I can't see any data in the zip file after I download, it will be just like an empty text file
res.status(200).sendFile('./ABC.zip');
and it is a get request. tried setting
res.set('Content-Disposition', 'attachment; filename=file.zip');
res.set('Content-Type', 'application/zip');
But didn't help. do I need to set few more parameters for response object..?? please help
const downloadName = `${Date.now()}.zip`;
const data = zip.toBuffer();
res.set('Content-Type','application/octet-stream');
res.set('Content-Disposition',`attachment; filename=${downloadName}`);
res.set('Content-Length',data.length);
res.send(data);

nodejs - change contents of zip file without re-generating the whole archive

I'm using node-zip (which uses JSZip under the hood). I need to modify the contents of a zip file, and I'd love to be able to modify it without generating the entire zip again, because it can take a long time for large archives. Here's an example:
var zip = new JSZip()
// Add some files to the zip
zip.file('file1', "file 1 contents\n")
zip.file('file2', "file 2 contents\n")
zip.file('file3', "file 3 contents\n")
// Generate the zip file
buffer = zip.generate()
// Make some changes
zip.file('file1', "changed file contents\n")
// Now I have to generate the entire zip again to get the buffer
buffer = zip.generate()
How can I do something like
updatedBuffer = zip.updateFile(buffer, 'file1', 'changed file contents\n')
Where I get an updated archive buffer but I only have to spend CPU cycles updating the one file
Assuming JSZip v2 here (zip.generate()):
You can get the buffer with asNodeBuffer(), modify it and update the content for your file:
var buffer = zip.file("file1").asNodeBuffer();
// change buffer
zip.file("file1", buffer);
Edit: if you mean editing in place a zip file stored on disk: no, JSZip can't do that.

Resources