Ich habe eine Web-App, mit der Benutzer Dateien hochladen können. Ich habe ein Google-Konto speziell für meine Webanwendung erstellt, z. B. [email protected] Ich möchte, dass jede Datei, die ein Nutzer aus meiner Web-App lädt, auf dem Google Drive meiner Web-App gespeichert wird. Ich verwende die folgende Methode, um eine Datei auf Google Drive hochzuladen und funktioniert einwandfrei. Aber das Problem ist die Datei wird auf dem Google Drive der Person selbst gespeichert, wenn er ein Google-Konto hat. Wo im Code kann ich sagen, um Datei auf [email protected] hochzuladen?Datei auf ein gemeinsames Google-Laufwerk hochladen
function uploadFile(evt) {
alert('Hello');
gapi.client.load('drive', 'v2', function() {
insertFile();
});
}
/**
* Insert new file.
*/
function insertFile() {
const boundary = '-------314159265358979323846264';
const delimiter = "\r\n--" + boundary + "\r\n";
const close_delim = "\r\n--" + boundary + "--";
var appState = {
number: 12,
text: 'hello'
};
var fileName = 'csusbdt-drive-example-app-state.txt';
var contentType = 'application/json';
var metadata = {
'title': fileName,
'mimeType': contentType
};
var base64Data = btoa(JSON.stringify(appState));
var multipartRequestBody =
delimiter +
'Content-Type: application/json\r\n\r\n' +
JSON.stringify(metadata) +
delimiter +
'Content-Type: ' + contentType + '\r\n' +
'Content-Transfer-Encoding: base64\r\n' +
'\r\n' +
base64Data +
close_delim;
var request = gapi.client.request({
'path': '/upload/drive/v2/files',
'method': 'POST',
'params': {'uploadType': 'multipart'},
'headers': {
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
},
'body': multipartRequestBody});
request.execute(function(arg) {
console.log(arg);
});
}
der letzte Absatz ist der wichtigste. Sie möchten serverseitigen Oauth-Flow, nicht clientseitig. –