You can use JSZIP.
**use npm to install JSZIP
let zip = require('jszip')();
//hoping you have already taken input
let input = document.getElementById('fileInput'); // fileInput is id of my input element
let file = input.files[0];
let allZip = zip.file(file.name, file);
console.log(allZip)
Answer from Ashish Yadav on Stack OverflowYou can use JSZIP.
**use npm to install JSZIP
let zip = require('jszip')();
//hoping you have already taken input
let input = document.getElementById('fileInput'); // fileInput is id of my input element
let file = input.files[0];
let allZip = zip.file(file.name, file);
console.log(allZip)
Hi Garrick following are the steps you need to take.
1) handle fileupload in a rest wrapper https://marmelab.com/admin-on-rest/RestClients.html#decorating-your-rest-client-example-of-file-upload
the above example is for image upload. But you will essentially be doing the same thing.
2)
const addUploadCapabilities = requestHandler => (type, resource, params) => {
if (type === 'UPDATE' && resource === 'posts') {
//use jszip to zip file here and package it however you need
// call the API with zipped file
} return requestHandler(type, resource, params);
};
How to Extract and Use a ZIP File from the assets/ Folder in a React Native Project?
How to read the zip file contents in react application using jszip preferably
Download a zip file in reactjs without any plugins - Stack Overflow
reactjs - Download and zip files in React? - Stack Overflow
Videos
» npm install react-native-zip-archive
How can I extract a files.zip located inside the assets/ folder of a React Native project during app initialization and import the contained .json files?
I have a files.zip file in the assets/ folder, which contains .json data to be used in my app. I want to extract this zip file and import the .json files when the app starts. Here’s what I’ve tried so far:
Using
react-native-zip-archive: I attempted this, but encountered errors, likely due to version conflicts on iOS.Using
expo-file-systemandjszip: Unfortunately, I wasn’t familiar enough withexpo-file-systemto make it work.Using
requireto load the zip file: When I logged the output of requiring the zip file, I only got the number40. It seems like the zip file isn’t being loaded properly.
Is it not possible to load a zip file directly this way? Are there any alternative approaches to solve this issue?
Here’s my project setup:
"expo": "~52.0.7""react-native": "0.76.5
I started this project using the Ignite boilerplate.
Any advice would be greatly appreciated!
react-native-zip-archive error