Open Khaptikma opened 1 year ago
Hi there, Yes, it can 🙂. Any problem with that?
I have succeeded to list all my files in drive, but I think I have a trouble finding out how to get list of my apps backup files in "backup" section. So can you help me out with that, please?
What's the trouble?
hi, i need help, would you like to share me a simple json file upload for scope of `auth/drive.appdata'? i'm stuck here. thx
Hi, Did you have a look at the docs and my sample project?
ok i somehow manage to create file, but i have some problem to retrieve the content. here is what i use:
const saveFileContent = await gDrive.files.getJson(saveFileId, {
spaces: 'appDataFolder',
});
and the error is:
HttpError: {
"error": {
"code": 404,
"message": "File not found: 1NrP0jSV5MvvnZ2Mwd-quMkXnBQFehWiiD6FP-tHbTtVy5Atuhh8.",
"errors": [
{
"message": "File not found: 1NrP0jSV5MvvnZ2Mwd-quMkXnBQFehWiiD6FP-tHbTtVy5Atuhh8.",
"domain": "global",
"reason": "notFound",
"location": "fileId",
"locationType": "parameter"
}
]
}
}
I'm using only auth/drive.appdata
scope
i created the file using:
const file = await gDrive.files.newMultipartUploader().setRequestBody({
name: saveFileName,
parents: ['appDataFolder']
}).setData(
JSON.stringify(getDefaultAuthenticatorData()), MimeTypes.JSON
).execute();
i can see the file if i use
const filesResponse = await gDrive.files.list({
spaces: 'appDataFolder',
});
Sorry for the long delay. Is the issue still relevant for you?
hi, yes it still relevant. Actually would you able to create a snippet of code that demonstrate the usage of per-app data folder usage? that would be helpful
ok actually my issue is that i have the following code:
return this.driveInstance.files.newMultipartUploader().setRequestBody({
name: 'my-test.json',
parents: ['appDataFolder']
}).setData(
JSON.stringify({timestamp: now.getTime()}), MimeTypes.JSON
).execute();
to always get [AbortError: Aborted]
, any idea?
Hi @hansyulian, I'll try to find some time to create a sample snippet.
As for the error you get, I don't have an idea yet, sorry. Please, let's wait for a sample.
@hansyulian I am not sure if you are stuck, but it works for me. The following code checks existing backup, uploads new backup, deletes old backup and also fetches the new backup
if (GoogleSignin.getCurrentUser() === null) {
setGoogleUser(await signInGoogleForDrive())
}
const gDrive = new GDrive()
gDrive.accessToken = (await GoogleSignin.getTokens()).accessToken
gDrive.fetchCoercesTypes = true
gDrive.fetchRejectsOnHttpErrors = true
gDrive.fetchTimeout = 3000
const backupFilesData = await gDrive.files.list({
spaces: 'appDataFolder',
})
const filesToDelete: string[] = []
if (backupFilesData.files.length > 0) {
for (const file of backupFilesData.files) {
filesToDelete.push(file.id)
}
}
await gDrive.files
.newMultipartUploader()
.setRequestBody({
name: 'backup.json',
parents: ['appDataFolder'],
})
.setData(JSON.stringify(backupData), MimeTypes.JSON)
.execute()
for (const fileId of filesToDelete) {
await gDrive.files.delete(fileId)
}
const f = await gDrive.files.list({
spaces: 'appDataFolder',
})
console.log(f)
const fileId = f.files[0].id
console.log('Backup file ID:', fileId)
const downloadResponse = await gDrive.files.getJson(fileId)
console.log('Backup JSON data:', downloadResponse)
@RobinBobin I get the error in Android
[AbortError: Aborted]
Works fine in ios
On further investigation, The issue is with Timeout. Increase it, and it will work.
It looks like everything's sorted. Can I close the issue?
Greetings. Can this library store application specific data as in:
https://developers.google.com/drive/api/guides/appdata ?