Tôi có một đoạn mã phía máy khách xuất tệp .docx từ Google Drive và gửi dữ liệu đến máy chủ của tôi. Nó khá thẳng về phía trước, nó chỉ xuất khẩu các tập tin, làm cho nó thành một blob, và gửi blob đến một điểm cuối POST.Tại sao tôi không thể trích xuất tệp zip từ yêu cầu POST?
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);
});
Đây là mã phía máy chủ của tôi để lưu file này vào máy chủ của tôi để tôi có thể làm việc với nó:
<?php
file_put_contents('tmp/document.docx', fopen('php://input', 'r'));
Khi tôi chạy này, các tập tin được tạo ra trên máy chủ của tôi. Tuy nhiên, tôi tin rằng nó bị hỏng, bởi vì khi tôi cố gắng để giải nén nó (như bạn có thể làm với .docx), điều này xảy ra:
$ 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)
Tại sao phải không thừa nhận nó như là một tập tin .zip thích hợp?
Lưu ý cho người đọc trong tương lai: Tôi vẫn không chắc chắn cách thực hiện việc này.Tôi nghĩ rằng tôi đã cố gắng hết sức để phù hợp với một hình zip-file hình thành một lỗ hình dạng truy cập-token. Vì vậy, tôi đã tái cơ cấu ứng dụng để thực hiện các cuộc gọi xuất khẩu gapi trên phần phụ trợ và thực hiện các công cụ với dữ liệu được trích xuất ở đó. –