मेरे पास क्लाइंट साइड कोड का एक टुकड़ा है जो Google ड्राइव से .docx फ़ाइल निर्यात करता है और डेटा को मेरे सर्वर पर भेजता है। यह बहुत सीधी आगे है, यह सिर्फ फाइल निर्यात करता है, इसे ब्लॉब में बनाता है, और ब्लॉब को पोस्ट एंडपॉइंट पर भेजता है।मैं POST अनुरोध से ज़िप फ़ाइल क्यों नहीं निकाल सकता?
<?php
file_put_contents('tmp/document.docx', fopen('php://input', 'r'));
जब मैं इस चलाने के लिए, फ़ाइल को अपने सर्वर पर बनाई गई है:
gapi.client.drive.files.export({
fileId: file_id,
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}).then(function (response) {
// the zip file data is now in response.body
var blob = new Blob([response.body], {type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"});
// send the blob to the server to extract
var request = new XMLHttpRequest();
request.open('POST', 'return-xml.php', true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onload = function() {
// the extracted data is in the request.responseText
// do something with it
};
request.send(blob);
});
यहाँ मेरी सर्वर पर इस फ़ाइल को सहेजने के लिए मेरे सर्वर साइड कोड तो मैं इसके साथ कर सकते हैं है। हालांकि, मेरा मानना है कि यह दूषित है, क्योंकि जब मैं इसे अनज़िप करने के लिए (जैसा कि आप .docx साथ कर सकते हैं) की कोशिश, ऐसा होता है:
$ mv tmp/document.docx tmp/document.zip
$ unzip tmp/document.zip
Archive: document.zip
error [document.zip]: missing 192760059 bytes in zipfile
(attempting to process anyway)
error [document.zip]: start of central directory not found;
zipfile corrupt.
(please check that you have transferred or created the zipfile in the
appropriate BINARY mode and that you have compiled UnZip properly)
क्यों नहीं यह यह एक उचित .zip फ़ाइल के रूप को पहचानना है?
भावी पाठक के लिए नोट: मुझे अभी भी यह सुनिश्चित नहीं है कि यह कैसे करें।मुझे लगता है कि मैं एक ज़िप-फ़ाइल-आकार वाले पेग को एक्सेस-टोकन-आकार वाले छेद में फिट करने के लिए बहुत मेहनत कर रहा था। इसलिए, मैंने बैकएंड पर गैसी निर्यात कॉल करने के लिए एप्लिकेशन को पुनर्गठित किया और वहां निकाले गए डेटा के साथ सामान किया। –