问题
This is the code to upload image on my Google Drive, then get the url and delete if needed and it was working perfectly.
function uploadImageInFolderAndGetVisibleDocURL(imgName, url) {
return new Promise(function(resolve, reject) {
const fileName = imgName;
var folderId = '01220GsMOG727b2TxnSB_7zkgAFcygd';
fetch(url).then(res => res.blob()).then(blob => {
const form = new FormData();
form.append('metadata', new Blob([JSON.stringify({name: fileName, parents: [folderId]})], {type: 'application/json'}));
form.append('file', blob);
fetch('https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart', {
method: 'POST',
headers: new Headers({'Authorization': 'Bearer ' + gapi.auth.getToken().access_token}),
body: form
}).then(res => res.json()).then(val => resolve(["https://drive.google.com/uc?id="+val.id, val.id]));
});
});
}
function deleteGoogleDocImageByPhotoID(photoID) {
return new Promise(function(resolve, reject) {
var request = gapi.client.drive.files.delete({
'fileId': photoID
});
request.execute(function(resp) {
resolve("success");
});
});
}
Today I made another Project on Google Console with different Google account. Here I gave different name of my project. I got different apiKey
& clientId
. But when It comes to provide the main URL and redirect url on my Google Developer Console, I put the same, because my web app url is fixed and it's the one I got. I have enabled the Google Drive API on my new Google Console and the parents folder in which I am uploading my image is set to public just like my previous account.
But strangely It is giving me this error while uploading image:POST https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart 403
Point to this line:fetch('https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart',
When I come back to my code and set my previous apiKey
& clientId
and run project it's still giving me the same error. But this was working perfectly before setting up the 2nd new project on different Google Account. Why is this happening? Any suggestions would be highly appreciated.
Thanks a lot in advanced.
PS: I run my project on Chrome incognito mode.
Error in expand mode:
(anonymous) @ upload.js:87
Promise.then (async)
(anonymous) @ upload.js:82
uploadImageInFolderAndGetVisibleDocURL @ upload.js:80
postOnGoogleDrive @ wallpapers.js:138
(anonymous) @ wallpapers.js:203
e.g @ promise.js:832
ae @ promise.js:1171
oe @ promise.js:1145
t.Zb @ promise.js:1116
Kt @ run.js:132
Promise.then (async)
Dt @ run.js:63
Ut @ run.js:42
ie @ promise.js:1034
ee @ promise.js:927
t.Oc @ promise.js:870
(anonymous) @ promise.js:996
Promise.then (async)
(anonymous) @ promise.js:1008
ne @ promise.js:1010
ee @ promise.js:916
(anonymous) @ promise.js:175
e.g @ promise.js:832
ae @ promise.js:1171
oe @ promise.js:1145
t.Zb @ promise.js:1116
Kt @ run.js:132
Promise.then (async)
Dt @ run.js:63
Ut @ run.js:42
ie @ promise.js:1034
Qt @ promise.js:797
te @ promise.js:853
qt.then @ promise.js:577
t.cc @ auth.js:1485
Ve.getAuthToken @ authwrapper.ts:96
qe.getDownloadURL @ reference.ts:336
complete @ wallpapers.js:199
(anonymous) @ async.ts:26
Promise.then (async)
(anonymous) @ async.ts:26
Be.notifyObserver_ @ task.ts:637
(anonymous) @ task.ts:599
Be.notifyObservers_ @ task.ts:598
Be.transition_ @ task.ts:418
(anonymous) @ task.ts:284
Promise.then (async)
(anonymous) @ task.ts:278
(anonymous) @ task.ts:177
e.g @ promise.js:832
ae @ promise.js:1171
oe @ promise.js:1145
t.Zb @ promise.js:1116
Kt @ run.js:132
Promise.then (async)
Dt @ run.js:63
Ut @ run.js:42
ie @ promise.js:1034
Qt @ promise.js:797
te @ promise.js:853
qt.then @ promise.js:577
t.cc @ auth.js:1485
Ve.getAuthToken @ authwrapper.ts:96
Be.resolveToken_ @ task.ts:174
Be.continueUpload_ @ task.ts:253
Be.start_ @ task.ts:163
Be.completeTransitions_ @ task.ts:433
(anonymous) @ task.ts:286
Promise.then (async)
(anonymous) @ task.ts:278
(anonymous) @ task.ts:177
e.g @ promise.js:832
ae @ promise.js:1171
oe @ promise.js:1145
t.Zb @ promise.js:1116
Kt @ run.js:132
Promise.then (async)
Dt @ run.js:63
Ut @ run.js:42
ie @ promise.js:1034
Qt @ promise.js:797
te @ promise.js:853
qt.then @ promise.js:577
t.cc @ auth.js:1485
Ve.getAuthToken @ authwrapper.ts:96
Be.resolveToken_ @ task.ts:174
Be.continueUpload_ @ task.ts:253
Be.start_ @ task.ts:163
Be.completeTransitions_ @ task.ts:433
(anonymous) @ task.ts:286
来源:https://stackoverflow.com/questions/63555056/getting-permission-denied-error-while-uploading-image-on-google-drive-by-google