Mi sto imbattendo in un problema durante il recupero di un file binario da Drive utilizzando l'API, continuo ad andare in circolo.Lettura di un file binario da Google Drive tramite node.js
Ecco i bit di codice rilevante:
// Load client secrets from a local file.
fs.readFile('client_secret.json', function processClientSecrets(err, content) {
if (err) {
console.log('Error loading client secret file: ' + err);
return;
}
// Authorize a client with the loaded credentials, then call the
// Drive API.
oauth.authorize(JSON.parse(content), dasm.init, driveapi.getFile)
});
driveapi.getFile:
function getFile(auth, cb) {
var service = google.drive('v3');
service.files.get({
auth: auth,
pageSize: 20,
fileId: "0B2h-dgPh8_5CZE9WZVM4a3BxV00",
alt: 'media'
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
cb(response)
});
}
Ora, response
sembra essere a tornare come una stringa. Quando provo a convertire in esadecimale, diventa matto. C'è un modo per prendere response
e portarlo in un Buffer
? O è corrotto il sec ho capito da service.files.get
?
da noci, voglio dire che
console.log(
arrData[0].charCodeAt(0).toString(2),
'-',
arrData[1].charCodeAt(0).toString(2),
'-',
arrData[2].charCodeAt(0).toString(2),
'-',
arrData[3].charCodeAt(0).toString(2),
'-',
arrData[4].charCodeAt(0).toString(2)
)
= 1001101 - 1.011.010-1111111111111101 - 0-11 (sto usando binario per cercare di vedere ciò che è rotto)
la correttezza esadecimale sarebbe 4D 5A 90 00 03
Edit: per coloro che sono confusi, come se fossi, come 90
diventato fffd
è il Unicode replacement character che viene visualizzato quando il valore non mappa a un carattere ASCII.
Questo esempio sembra funzionare solo quando si imposta 'responseType = "ArrayBuffer"', qualcosa che non sembrano essere in grado di fare con API Drive. Il tuo esempio di codice restituisce un oggetto generico di lunghezza zero. – Drazisil