I am developing a website using react.js and admin-on-rest. One feature is allowing users to upload a pdf file.
I get the file as type FILE
and want to get the file from FILE
, compress it to zip, and then make it to type FILE
.
So it should be FILE
-> origin file -> zip file -> FILE
from zip file.
I tried JSZip but still can not figure it out.
Any help is appreciated. Thanks
Advertisement
Answer
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)
JavaScript
x
7
1
const addUploadCapabilities = requestHandler => (type, resource, params) => {
2
if (type === 'UPDATE' && resource === 'posts') {
3
//use jszip to zip file here and package it however you need
4
// call the API with zipped file
5
} return requestHandler(type, resource, params);
6
};
7