Error while uploading file to Google Drive

2019-04-29 11:43发布

问题:

I have implement Google Drive SDK in my app project. and try to upload an image in Google Drive But I got Error.

I do code from Here

when i run this code I got Below Error

Error Domain=com.google.GTLJSONRPCErrorDomain Code=400 "The operation couldn’t be completed. (Invalid Value)" UserInfo=0x276940 {NSLocalizedFailureReason=(Invalid Value), GTLStructuredError=GTLErrorObject 0x2fade0: {message:"Invalid Value" code:400 data:[1]}, error=Invalid Value}

please give me suggestion for this. Thanks in advance

回答1:

I got same kind of error earlier. I think you did not authorized first with google drive, you should have to check it again by login with your google account. Have you logged in with google drive account before uploading file? If not then it may cause error. Also please try again with new regenerated client id and secret key.



回答2:

HI pratik i just google it and got some solution it might be it helps you. This Error occur becouse you are not set proparly image mimeType or Name.

Very recent changes in the Google Drive service obliges you to specify a mime type different than "application/json-rpc" when uploading a file. This mime type is used by default when using the ObjectiveC SDK, so you need to specify one.

GTLDriveFile *newFile = [GTLDriveFile object];
newFile.title = filename;
newFile.mimeType = @"image/png";

Edited: It also seems that there is temporary problem on Google's servers

source from:- Google drive integration in iOS giving error while calling insert

ans also it Seems like this was just a temporary issue with the Google Drive backend.



回答3:

Just in case it helps others who find this answer (as I did)...

I got the same error code when I failed to escape a single quote in one of the values of a parameter of the query:

 https://developers.google.com/drive/v2/web/search-parameters

I needed to use \ before ' so my 'value\'was\'valid' ...