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)
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); };