Google Drive Api for Service account. Error while creating a file (probably due to base64)2019 Community Moderator ElectionDisplaying files (e.g. images) stored in Google Drive on a websitechange Google Drive mimeType on update fileHow to create a public Google Doc through the Drive API (PHP client)how to upload file to google drive using sdk in uploadtype=mediaOauth2 Google Drive offline access not working for non-google app files?Google Drive REST API update content as HTML with Landscape Orientation google-drive-sdkUpload Files to GOOGLE DRIVE without user authentication only when form submitted in LARAVEL OR AJAXCan not create folder using multipartPyDrive: Create a Google Doc fileGoogle Drive Uploading multipart mime base64 encoded file w/powershell: malformed multipart body error

Is divide-by-zero a security vulnerability?

Is the differential, dp, exact or not?

Exempt portion of equation line from aligning?

What is better: yes / no radio, or simple checkbox?

I've given my players a lot of magic items. Is it reasonable for me to give them harder encounters?

Why would /etc/passwd be used every time someone executes `ls -l` command?

Does an unused member variable take up memory?

Is this Paypal Github SDK reference really a dangerous site?

What is the oldest European royal house?

Propulsion Systems

I am the person who abides by rules but breaks the rules . Who am I

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Where is the License file location for Identity Server in Sitecore 9.1?

What should I do when a paper is published similar to my PhD thesis without citation?

3.5% Interest Student Loan or use all of my savings on Tuition?

Cycles on the torus

Is there a math expression equivalent to the conditional ternary operator?

Was this cameo in Captain Marvel computer generated?

School performs periodic password audits. Is my password compromised?

Will the concrete slab in a partially heated shed conduct a lot of heat to the unconditioned area?

If nine coins are tossed, what is the probability that the number of heads is even?

Why does this boat have a landing pad? (SpaceX's GO Searcher) Any plans for propulsive capsule landings?

Does the US political system, in principle, allow for a no-party system?

“I had a flat in the centre of town, but I didn’t like living there, so …”



Google Drive Api for Service account. Error while creating a file (probably due to base64)



2019 Community Moderator ElectionDisplaying files (e.g. images) stored in Google Drive on a websitechange Google Drive mimeType on update fileHow to create a public Google Doc through the Drive API (PHP client)how to upload file to google drive using sdk in uploadtype=mediaOauth2 Google Drive offline access not working for non-google app files?Google Drive REST API update content as HTML with Landscape Orientation google-drive-sdkUpload Files to GOOGLE DRIVE without user authentication only when form submitted in LARAVEL OR AJAXCan not create folder using multipartPyDrive: Create a Google Doc fileGoogle Drive Uploading multipart mime base64 encoded file w/powershell: malformed multipart body error










0















I've created a folder and a file w/ permission to access a file for any Internet user. I used to think upload itself worked properly. Unfortunately, when I use




https://drive.google.com/uc?export=view&id=file.id




command, all I see is a black square and when I trying to download via downloadLink file's property, it even couldn't be opened.



So, here's my code



private static String initiateResumable(string base64, string fileType)
String endpoint ='https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable';

map<String, Object> md = new map<String, Object>();

md.put('name', 'demofile');
md.put('parents', '[' + folderId + ']');

String metadata = JSON.serialize(md);

Integer size = Math.min(2000000, base64.length());

//return an HttpRequest object of POST method with
// Authorization token provided (JWT is used)
HttpRequest req = createRequest('post');

req.setEndpoint(endpoint);

req.setHeader('Content-Type', 'application/json; charset=UTF-8');
req.setHeader('Content-Length', String.valueOf(metadata.length()));
req.setHeader('X-Upload-Content-Type', fileType);
req.setHeader('X-Upload-Content-Length', String.valueOf(size));

req.setBody(metadata);

HttpResponse res = (new Http()).send(req);

return res.getHeader('Location');


private static File sendFile(String base64, String fileType, String endpoint)
Integer size = Math.min(2000000, base64.length());
HttpRequest req = createRequest('put');
HttpResponse res;

req.setEndpoint(endpoint);

req.setHeader('Content-Type', fileType);

while(! String.isBlank(base64))
final string buffer = base64.left(size);
base64 = base64.removeStart(buffer);

req.setHeader('Content-Length', String.valueOf(buffer.length()));
req.setBody(buffer);

res = (new Http()).send(req);


return (File)JSON.deserialize(res.getBody(), File.class);



I believe that's because of base64 format, but I may be wrong



The same error occurs with the following code:



 HttpRequest req = createRequest('get');
req.setEndpoint('https://www.googleapis.com/upload/drive/v3/files?uploadType=media');

req.setHeader('Content-Type', fileType);
req.setHeader('Content-Length',String.valueOf(base64.length()));
req.setHeader('Content-Transfer-Encoding', 'base64');

req.setBody(base64);

HttpResponse res = (new Http()).send(req);

File file = (File) JSON.deserialize(res.getBody(), File.class);

return file;


It's Salesforce's Apex so no way for any frameworks, but the syntax is quite straightforward, I believe



10q in advance










share|improve this question
























  • Could you share any errors from your logs?

    – MαπμQμαπkγVπ.0
    yesterday











  • Unfortunately, there are no errors. Meant to say, that's told by google drive API dashboard. Moreover, the file created could be retrieved via '/files' and '/files/fileId' HTTP requests both

    – being of habits
    yesterday












  • Probably, it could be useful. That's an Id of a file creted: 19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0 It's downloadURL: doc-08-0o-docs.googleusercontent.com/docs/securesc/… And embedURL : drive.google.com/file/d/19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0/…

    – being of habits
    yesterday















0















I've created a folder and a file w/ permission to access a file for any Internet user. I used to think upload itself worked properly. Unfortunately, when I use




https://drive.google.com/uc?export=view&id=file.id




command, all I see is a black square and when I trying to download via downloadLink file's property, it even couldn't be opened.



So, here's my code



private static String initiateResumable(string base64, string fileType)
String endpoint ='https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable';

map<String, Object> md = new map<String, Object>();

md.put('name', 'demofile');
md.put('parents', '[' + folderId + ']');

String metadata = JSON.serialize(md);

Integer size = Math.min(2000000, base64.length());

//return an HttpRequest object of POST method with
// Authorization token provided (JWT is used)
HttpRequest req = createRequest('post');

req.setEndpoint(endpoint);

req.setHeader('Content-Type', 'application/json; charset=UTF-8');
req.setHeader('Content-Length', String.valueOf(metadata.length()));
req.setHeader('X-Upload-Content-Type', fileType);
req.setHeader('X-Upload-Content-Length', String.valueOf(size));

req.setBody(metadata);

HttpResponse res = (new Http()).send(req);

return res.getHeader('Location');


private static File sendFile(String base64, String fileType, String endpoint)
Integer size = Math.min(2000000, base64.length());
HttpRequest req = createRequest('put');
HttpResponse res;

req.setEndpoint(endpoint);

req.setHeader('Content-Type', fileType);

while(! String.isBlank(base64))
final string buffer = base64.left(size);
base64 = base64.removeStart(buffer);

req.setHeader('Content-Length', String.valueOf(buffer.length()));
req.setBody(buffer);

res = (new Http()).send(req);


return (File)JSON.deserialize(res.getBody(), File.class);



I believe that's because of base64 format, but I may be wrong



The same error occurs with the following code:



 HttpRequest req = createRequest('get');
req.setEndpoint('https://www.googleapis.com/upload/drive/v3/files?uploadType=media');

req.setHeader('Content-Type', fileType);
req.setHeader('Content-Length',String.valueOf(base64.length()));
req.setHeader('Content-Transfer-Encoding', 'base64');

req.setBody(base64);

HttpResponse res = (new Http()).send(req);

File file = (File) JSON.deserialize(res.getBody(), File.class);

return file;


It's Salesforce's Apex so no way for any frameworks, but the syntax is quite straightforward, I believe



10q in advance










share|improve this question
























  • Could you share any errors from your logs?

    – MαπμQμαπkγVπ.0
    yesterday











  • Unfortunately, there are no errors. Meant to say, that's told by google drive API dashboard. Moreover, the file created could be retrieved via '/files' and '/files/fileId' HTTP requests both

    – being of habits
    yesterday












  • Probably, it could be useful. That's an Id of a file creted: 19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0 It's downloadURL: doc-08-0o-docs.googleusercontent.com/docs/securesc/… And embedURL : drive.google.com/file/d/19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0/…

    – being of habits
    yesterday













0












0








0








I've created a folder and a file w/ permission to access a file for any Internet user. I used to think upload itself worked properly. Unfortunately, when I use




https://drive.google.com/uc?export=view&id=file.id




command, all I see is a black square and when I trying to download via downloadLink file's property, it even couldn't be opened.



So, here's my code



private static String initiateResumable(string base64, string fileType)
String endpoint ='https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable';

map<String, Object> md = new map<String, Object>();

md.put('name', 'demofile');
md.put('parents', '[' + folderId + ']');

String metadata = JSON.serialize(md);

Integer size = Math.min(2000000, base64.length());

//return an HttpRequest object of POST method with
// Authorization token provided (JWT is used)
HttpRequest req = createRequest('post');

req.setEndpoint(endpoint);

req.setHeader('Content-Type', 'application/json; charset=UTF-8');
req.setHeader('Content-Length', String.valueOf(metadata.length()));
req.setHeader('X-Upload-Content-Type', fileType);
req.setHeader('X-Upload-Content-Length', String.valueOf(size));

req.setBody(metadata);

HttpResponse res = (new Http()).send(req);

return res.getHeader('Location');


private static File sendFile(String base64, String fileType, String endpoint)
Integer size = Math.min(2000000, base64.length());
HttpRequest req = createRequest('put');
HttpResponse res;

req.setEndpoint(endpoint);

req.setHeader('Content-Type', fileType);

while(! String.isBlank(base64))
final string buffer = base64.left(size);
base64 = base64.removeStart(buffer);

req.setHeader('Content-Length', String.valueOf(buffer.length()));
req.setBody(buffer);

res = (new Http()).send(req);


return (File)JSON.deserialize(res.getBody(), File.class);



I believe that's because of base64 format, but I may be wrong



The same error occurs with the following code:



 HttpRequest req = createRequest('get');
req.setEndpoint('https://www.googleapis.com/upload/drive/v3/files?uploadType=media');

req.setHeader('Content-Type', fileType);
req.setHeader('Content-Length',String.valueOf(base64.length()));
req.setHeader('Content-Transfer-Encoding', 'base64');

req.setBody(base64);

HttpResponse res = (new Http()).send(req);

File file = (File) JSON.deserialize(res.getBody(), File.class);

return file;


It's Salesforce's Apex so no way for any frameworks, but the syntax is quite straightforward, I believe



10q in advance










share|improve this question
















I've created a folder and a file w/ permission to access a file for any Internet user. I used to think upload itself worked properly. Unfortunately, when I use




https://drive.google.com/uc?export=view&id=file.id




command, all I see is a black square and when I trying to download via downloadLink file's property, it even couldn't be opened.



So, here's my code



private static String initiateResumable(string base64, string fileType)
String endpoint ='https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable';

map<String, Object> md = new map<String, Object>();

md.put('name', 'demofile');
md.put('parents', '[' + folderId + ']');

String metadata = JSON.serialize(md);

Integer size = Math.min(2000000, base64.length());

//return an HttpRequest object of POST method with
// Authorization token provided (JWT is used)
HttpRequest req = createRequest('post');

req.setEndpoint(endpoint);

req.setHeader('Content-Type', 'application/json; charset=UTF-8');
req.setHeader('Content-Length', String.valueOf(metadata.length()));
req.setHeader('X-Upload-Content-Type', fileType);
req.setHeader('X-Upload-Content-Length', String.valueOf(size));

req.setBody(metadata);

HttpResponse res = (new Http()).send(req);

return res.getHeader('Location');


private static File sendFile(String base64, String fileType, String endpoint)
Integer size = Math.min(2000000, base64.length());
HttpRequest req = createRequest('put');
HttpResponse res;

req.setEndpoint(endpoint);

req.setHeader('Content-Type', fileType);

while(! String.isBlank(base64))
final string buffer = base64.left(size);
base64 = base64.removeStart(buffer);

req.setHeader('Content-Length', String.valueOf(buffer.length()));
req.setBody(buffer);

res = (new Http()).send(req);


return (File)JSON.deserialize(res.getBody(), File.class);



I believe that's because of base64 format, but I may be wrong



The same error occurs with the following code:



 HttpRequest req = createRequest('get');
req.setEndpoint('https://www.googleapis.com/upload/drive/v3/files?uploadType=media');

req.setHeader('Content-Type', fileType);
req.setHeader('Content-Length',String.valueOf(base64.length()));
req.setHeader('Content-Transfer-Encoding', 'base64');

req.setBody(base64);

HttpResponse res = (new Http()).send(req);

File file = (File) JSON.deserialize(res.getBody(), File.class);

return file;


It's Salesforce's Apex so no way for any frameworks, but the syntax is quite straightforward, I believe



10q in advance







google-api google-drive-sdk jwt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







being of habits

















asked 2 days ago









being of habitsbeing of habits

394




394












  • Could you share any errors from your logs?

    – MαπμQμαπkγVπ.0
    yesterday











  • Unfortunately, there are no errors. Meant to say, that's told by google drive API dashboard. Moreover, the file created could be retrieved via '/files' and '/files/fileId' HTTP requests both

    – being of habits
    yesterday












  • Probably, it could be useful. That's an Id of a file creted: 19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0 It's downloadURL: doc-08-0o-docs.googleusercontent.com/docs/securesc/… And embedURL : drive.google.com/file/d/19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0/…

    – being of habits
    yesterday

















  • Could you share any errors from your logs?

    – MαπμQμαπkγVπ.0
    yesterday











  • Unfortunately, there are no errors. Meant to say, that's told by google drive API dashboard. Moreover, the file created could be retrieved via '/files' and '/files/fileId' HTTP requests both

    – being of habits
    yesterday












  • Probably, it could be useful. That's an Id of a file creted: 19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0 It's downloadURL: doc-08-0o-docs.googleusercontent.com/docs/securesc/… And embedURL : drive.google.com/file/d/19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0/…

    – being of habits
    yesterday
















Could you share any errors from your logs?

– MαπμQμαπkγVπ.0
yesterday





Could you share any errors from your logs?

– MαπμQμαπkγVπ.0
yesterday













Unfortunately, there are no errors. Meant to say, that's told by google drive API dashboard. Moreover, the file created could be retrieved via '/files' and '/files/fileId' HTTP requests both

– being of habits
yesterday






Unfortunately, there are no errors. Meant to say, that's told by google drive API dashboard. Moreover, the file created could be retrieved via '/files' and '/files/fileId' HTTP requests both

– being of habits
yesterday














Probably, it could be useful. That's an Id of a file creted: 19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0 It's downloadURL: doc-08-0o-docs.googleusercontent.com/docs/securesc/… And embedURL : drive.google.com/file/d/19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0/…

– being of habits
yesterday





Probably, it could be useful. That's an Id of a file creted: 19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0 It's downloadURL: doc-08-0o-docs.googleusercontent.com/docs/securesc/… And embedURL : drive.google.com/file/d/19FHn4Lxke_10exvF-C0Z4OjI3pnr77I0/…

– being of habits
yesterday












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027804%2fgoogle-drive-api-for-service-account-error-while-creating-a-file-probably-due%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027804%2fgoogle-drive-api-for-service-account-error-while-creating-a-file-probably-due%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme