Using your code, I'm able to do exactly what you did - create a plain text file with the content 'this is a sample data'.
However, what I'm trying to do is upload an Excel file, and it does create a file but the content is corrupt. Have you managed to upload a file like that?
Hi Arnab, great article and very clear.
Using your code, I'm able to do exactly what you did - create a plain text file with the content 'this is a sample data'.
However, what I'm trying to do is upload an Excel file, and it does create a file but the content is corrupt. Have you managed to upload a file like that?
Did you change the mime types accordingly?
Try using the Oauth playground I linked. You will get the exact error message.
Hi Arnab,
Yes from what I can see I've followed your instructions - and the file does get uploaded - it just seems to be corrupt for some reason.
I've tried with an image and got the same result.
This is how it looks (I've tried making tweaks to what you provided but same result):
--foo_bar_baz
content-disposition: form-data; name="metadata"; filename="test.png"
content-type: application/json
{"name":"test.png","mimeType":"image/png"}
--foo_bar_baz
content-disposition: form-data; name="file"; filename="test.png"
content-type: image/png
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAJYCAMAAACJuGjuAAACdlBMVEUBCQMcHBIZHA8dGw0XGhAVGA4UFwwBBgICDAMDDwQSFgsPGA4eHA8QFAgXGQ0bGAweHBMOEgcXFwscHBAFEQYlHhQLFQsMEgYlHBIoHA4VFwkc.. etc
--foo_bar_baz--
And I get my response like so:
{
"kind": "drive#file",
"id": "13Htxa1Lcfk_VyDDtZPj0yYBrs2_zwO4u",
"name": "test.png",
"mimeType": "image/png"
}
Let me know if you have any ideas.
Thanks,
Kevin
I managed to upload picture and video by modifying this snippet
gist.github.com/tanaikech/bd53b366...
Hope this help!