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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page